Skip to content

Commit

Permalink
Revert "Use version check for pending intent mutability flags"
Browse files Browse the repository at this point in the history
This reverts commit bf21958.
  • Loading branch information
premnirmal committed Aug 16, 2021
1 parent 64e4462 commit e08190e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.app.AlarmManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.core.content.getSystemService
import androidx.work.BackoffPolicy.LINEAR
import androidx.work.Constraints
Expand Down Expand Up @@ -138,12 +137,8 @@ class AlarmScheduler {
}
val refreshReceiverIntent = Intent(context, RefreshReceiver::class.java)
val alarmManager = checkNotNull(context.getSystemService<AlarmManager>())
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.getBroadcast(context, 0, refreshReceiverIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_ONE_SHOT)
} else {
PendingIntent.getBroadcast(context, 0, refreshReceiverIntent, PendingIntent.FLAG_ONE_SHOT)
}
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, clock.elapsedRealtime() + msToNextAlarm, pendingIntent)
val pendingIntent = PendingIntent.getBroadcast(context, 0, refreshReceiverIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_ONE_SHOT)
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, clock.elapsedRealtime() + msToNextAlarm, pendingIntent)
return nextAlarmDate
}

Expand Down Expand Up @@ -174,12 +169,9 @@ class AlarmScheduler {
Timber.d("enqueueDailySummaryNotification delay:${initialDelay}ms")
val receiverIntent = Intent(context, DailySummaryNotificationReceiver::class.java)
val alarmManager = checkNotNull(context.getSystemService<AlarmManager>())
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.getBroadcast(context, REQUEST_CODE_SUMMARY_NOTIFICATION, receiverIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_ONE_SHOT)
} else {
PendingIntent.getBroadcast(context, REQUEST_CODE_SUMMARY_NOTIFICATION, receiverIntent, PendingIntent.FLAG_ONE_SHOT)
}
alarmManager.setRepeating(
val pendingIntent =
PendingIntent.getBroadcast(context, REQUEST_CODE_SUMMARY_NOTIFICATION, receiverIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_ONE_SHOT)
alarmManager.setRepeating(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
clock.elapsedRealtime() + initialDelay,
interval,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,7 @@ private class NotificationFactory(
// Add the intent, which inflates the back stack
addNextIntentWithParentStack(intent)
// Get the PendingIntent containing the entire back stack
if (VERSION.SDK_INT >= VERSION_CODES.S) {
getPendingIntent(notificationId, PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
} else {
getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT)
}
getPendingIntent(notificationId, PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
}
val icon = when {
topQuotes.map { it.changeInPercent }.average() >= 2f -> R.drawable.ic_trending_up
Expand Down Expand Up @@ -348,11 +344,7 @@ private class NotificationFactory(
// Add the intent, which inflates the back stack
addNextIntent(intent)
// Get the PendingIntent containing the entire back stack
if (VERSION.SDK_INT >= VERSION_CODES.S) {
getPendingIntent(notificationId, PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
} else {
getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT)
}
getPendingIntent(notificationId, PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
}
with(notificationManager) {
// NotificationId is a unique int for each notification.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.appwidget.AppWidgetProvider
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.RemoteViews
Expand Down Expand Up @@ -143,11 +142,8 @@ class StockWidget : AppWidgetProvider() {
remoteViews.setEmptyView(R.id.list, R.layout.widget_empty_view)
val intent = Intent(context, WidgetClickReceiver::class.java)
intent.action = WidgetClickReceiver.CLICK_BCAST_INTENTFILTER
val flipIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val flipIntent =
PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
} else {
PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
remoteViews.setPendingIntentTemplate(R.id.list, flipIntent)
val lastUpdatedText = when (val fetchState = stocksProvider.fetchState) {
is FetchState.Success -> context.getString(R.string.last_fetch, fetchState.displayString)
Expand Down Expand Up @@ -177,16 +173,11 @@ class StockWidget : AppWidgetProvider() {
}
val updateReceiverIntent = Intent(context, RefreshReceiver::class.java)
updateReceiverIntent.action = AppPreferences.UPDATE_FILTER
val refreshPendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val refreshPendingIntent =
PendingIntent.getBroadcast(
context.applicationContext, 0, updateReceiverIntent,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
} else {
PendingIntent.getBroadcast(
context.applicationContext, 0, updateReceiverIntent, PendingIntent.FLAG_UPDATE_CURRENT
)
}
remoteViews.setOnClickPendingIntent(R.id.refresh_icon, refreshPendingIntent)
appWidgetManager.updateAppWidget(appWidgetId, remoteViews)
}
Expand Down
4 changes: 2 additions & 2 deletions app/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
versionName=3.9.746
versionCode=300900746
versionName=3.9.747
versionCode=300900747

0 comments on commit e08190e

Please sign in to comment.