expo-notifications 0.15.1 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,16 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 0.15.2 — 2022-05-05
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - Fixed Android 12+ runtime crash caused by `PendingIntent` misconfiguration. ([#17333](https://github.com/expo/expo/pull/17333) by [@kudo](https://github.com/kudo))
18
+
19
+ ### ⚠️ Notices
20
+
21
+ - Fixed exception on Android 12+ devices for missing `SCHEDULE_EXACT_ALARM` permission. If `scheduleNotificationAsync` needs a precise timer, the `SCHEDULE_EXACT_ALARM` should be explicitly added to **AndroidManifest.xml**. ([#17334](https://github.com/expo/expo/pull/17334) by [@kudo](https://github.com/kudo))
22
+
13
23
  ## 0.15.1 — 2022-04-27
14
24
 
15
25
  ### 💡 Others
package/README.md CHANGED
@@ -47,6 +47,8 @@ In order to be able to receive push notifications on the device ensure that your
47
47
 
48
48
  This module requires permission to subscribe to device boot. It's used to setup the scheduled notifications right after the device (re)starts. The `RECEIVE_BOOT_COMPLETED` permission is added automatically.
49
49
 
50
+ **Note:** Starting from Android 12 (API level 31), to schedule the notification that triggers at the exact time, you need to add `<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>` to **AndroidManifest.xml**. You can read more about the exact alarm permission [here](https://developer.android.com/about/versions/12/behavior-changes-12#exact-alarm-permission).
51
+
50
52
  <details><summary><strong>Expand to view how the notification icon and the default color can be customized in a plain React Native app</strong></summary> <p>
51
53
 
52
54
  - **To customize the icon**:
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '0.15.1'
6
+ version = '0.15.2'
7
7
 
8
8
  buildscript {
9
9
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
@@ -74,7 +74,7 @@ android {
74
74
  minSdkVersion safeExtGet("minSdkVersion", 21)
75
75
  targetSdkVersion safeExtGet("targetSdkVersion", 31)
76
76
  versionCode 21
77
- versionName '0.15.1'
77
+ versionName '0.15.2'
78
78
  }
79
79
 
80
80
  lintOptions {
@@ -7,20 +7,10 @@ import android.content.Context
7
7
  import android.content.Intent
8
8
  import android.content.pm.ActivityInfo
9
9
  import android.net.Uri
10
- import android.os.Bundle
11
- import android.os.Parcel
12
- import android.os.Parcelable
13
- import android.os.ResultReceiver
10
+ import android.os.*
14
11
  import android.util.Log
15
12
  import androidx.core.app.RemoteInput
16
- import expo.modules.notifications.notifications.model.Notification
17
- import expo.modules.notifications.notifications.model.NotificationAction
18
- import expo.modules.notifications.notifications.model.NotificationBehavior
19
- import expo.modules.notifications.notifications.model.NotificationCategory
20
- import expo.modules.notifications.notifications.model.NotificationRequest
21
- import expo.modules.notifications.notifications.model.NotificationResponse
22
- import expo.modules.notifications.notifications.model.TextInputNotificationAction
23
- import expo.modules.notifications.notifications.model.TextInputNotificationResponse
13
+ import expo.modules.notifications.notifications.model.*
24
14
  import expo.modules.notifications.service.delegates.ExpoCategoriesDelegate
25
15
  import expo.modules.notifications.service.delegates.ExpoHandlingDelegate
26
16
  import expo.modules.notifications.service.delegates.ExpoPresentationDelegate
@@ -424,11 +414,13 @@ open class NotificationsService : BroadcastReceiver() {
424
414
  intent.putExtra(IDENTIFIER_KEY, identifier)
425
415
  }
426
416
 
417
+ // We're defaulting to the behaviour prior API 31 (mutable) even though Android recommends immutability
418
+ val mutableFlag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0
427
419
  return PendingIntent.getBroadcast(
428
420
  context,
429
421
  intent.component?.className?.hashCode() ?: NotificationsService::class.java.hashCode(),
430
422
  intent,
431
- PendingIntent.FLAG_UPDATE_CURRENT
423
+ PendingIntent.FLAG_UPDATE_CURRENT or mutableFlag
432
424
  )
433
425
  }
434
426
 
@@ -458,11 +450,13 @@ open class NotificationsService : BroadcastReceiver() {
458
450
  intent.putExtra(NOTIFICATION_ACTION_KEY, action as Parcelable)
459
451
  }
460
452
 
453
+ // We're defaulting to the behaviour prior API 31 (mutable) even though Android recommends immutability
454
+ val mutableFlag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0
461
455
  return PendingIntent.getBroadcast(
462
456
  context,
463
457
  intent.component?.className?.hashCode() ?: NotificationsService::class.java.hashCode(),
464
458
  intent,
465
- PendingIntent.FLAG_UPDATE_CURRENT
459
+ PendingIntent.FLAG_UPDATE_CURRENT or mutableFlag
466
460
  )
467
461
  }
468
462
 
@@ -1,7 +1,9 @@
1
1
  package expo.modules.notifications.service.delegates
2
2
 
3
3
  import android.app.AlarmManager
4
+ import android.app.PendingIntent
4
5
  import android.content.Context
6
+ import android.os.Build
5
7
  import android.util.Log
6
8
  import androidx.core.app.AlarmManagerCompat
7
9
  import expo.modules.notifications.notifications.interfaces.SchedulableNotificationTrigger
@@ -57,12 +59,7 @@ class ExpoSchedulingDelegate(protected val context: Context) : SchedulingDelegat
57
59
  NotificationsService.removeScheduledNotification(context, request.identifier)
58
60
  } else {
59
61
  store.saveNotificationRequest(request)
60
- AlarmManagerCompat.setExactAndAllowWhileIdle(
61
- alarmManager,
62
- AlarmManager.RTC_WAKEUP,
63
- nextTriggerDate.time,
64
- NotificationsService.createNotificationTrigger(context, request.identifier)
65
- )
62
+ setupAlarm(nextTriggerDate.time, NotificationsService.createNotificationTrigger(context, request.identifier))
66
63
  }
67
64
  }
68
65
  }
@@ -99,4 +96,22 @@ class ExpoSchedulingDelegate(protected val context: Context) : SchedulingDelegat
99
96
  alarmManager.cancel(NotificationsService.createNotificationTrigger(context, it))
100
97
  }
101
98
  }
99
+
100
+ private fun setupAlarm(triggerAtMillis: Long, operation: PendingIntent) {
101
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || alarmManager.canScheduleExactAlarms()) {
102
+ AlarmManagerCompat.setExactAndAllowWhileIdle(
103
+ alarmManager,
104
+ AlarmManager.RTC_WAKEUP,
105
+ triggerAtMillis,
106
+ operation
107
+ )
108
+ } else {
109
+ AlarmManagerCompat.setAndAllowWhileIdle(
110
+ alarmManager,
111
+ AlarmManager.RTC_WAKEUP,
112
+ triggerAtMillis,
113
+ operation
114
+ )
115
+ }
116
+ }
102
117
  }
@@ -6,30 +6,30 @@
6
6
  <array>
7
7
  <dict>
8
8
  <key>LibraryIdentifier</key>
9
- <string>ios-arm64_x86_64-simulator</string>
9
+ <string>ios-arm64</string>
10
10
  <key>LibraryPath</key>
11
11
  <string>EXNotifications.framework</string>
12
12
  <key>SupportedArchitectures</key>
13
13
  <array>
14
14
  <string>arm64</string>
15
- <string>x86_64</string>
16
15
  </array>
17
16
  <key>SupportedPlatform</key>
18
17
  <string>ios</string>
19
- <key>SupportedPlatformVariant</key>
20
- <string>simulator</string>
21
18
  </dict>
22
19
  <dict>
23
20
  <key>LibraryIdentifier</key>
24
- <string>ios-arm64</string>
21
+ <string>ios-arm64_x86_64-simulator</string>
25
22
  <key>LibraryPath</key>
26
23
  <string>EXNotifications.framework</string>
27
24
  <key>SupportedArchitectures</key>
28
25
  <array>
29
26
  <string>arm64</string>
27
+ <string>x86_64</string>
30
28
  </array>
31
29
  <key>SupportedPlatform</key>
32
30
  <string>ios</string>
31
+ <key>SupportedPlatformVariant</key>
32
+ <string>simulator</string>
33
33
  </dict>
34
34
  </array>
35
35
  <key>CFBundlePackageType</key>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-notifications",
3
- "version": "0.15.1",
3
+ "version": "0.15.2",
4
4
  "description": "Notifications module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -58,5 +58,5 @@
58
58
  "peerDependencies": {
59
59
  "expo": "*"
60
60
  },
61
- "gitHead": "be6e0e7ea3f7fd1ab8368137260a7ad1b1bf12a8"
61
+ "gitHead": "b9d655c1bed682ad8919e071dd923968773f05b5"
62
62
  }