Skip to content

Commit

Permalink
πŸ› Change the flags for the notification to be IMMUTABLE
Browse files Browse the repository at this point in the history
This is related to the implicit intent changes in
e-mission/e-mission-docs#1079 (comment)

While testing local notifications, I got the error

```
java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.berkeley.eecs.emission/de.appplant.cordova.plugin.localnotification.ClickReceiver}:
java.lang.IllegalArgumentException: edu.berkeley.eecs.emission: Targeting U+ (version 34 and above) disallows creating or retrieving a PendingIntent with FLAG_MUTABLE, an implicit Intent within and without FLAG_NO_CREATE and FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT for security reasons.
To retrieve an already existing PendingIntent, use FLAG_NO_CREATE, however, to create a new PendingIntent with an implicit Intent use FLAG_IMMUTABLE.
```

In the original katzer repo the notification had IMMUTABLE flags, when the
code was copied over to bhandaribhumin it was changed to MUTABLE.

Changing it back to IMMUTABLE fixes the issue.

Testing done, after the fix, the transition is sent properly:

```
08-27 17:00:57.067 11959 12185 D local-notification: Scheduling inexact alarms with intent: PendingIntent{b58ad0c: android.os.BinderProxy@cc38655}
08-27 17:01:09.358   743   783 V WindowManagerShell: Transition requested: android.os.BinderProxy@721057c TransitionRequestInfo { type = OPEN, triggerTask = TaskInfo{userId=0 taskId=29 displayId=0 isRunning=true baseIntent=Intent { flg=0x5000c000 cmp=edu.berkeley.eecs.emission/de.appplant.cordova.plugin.localnotification.ClickReceiver } baseActivity=ComponentInfo{edu.berkeley.eecs.emission/de.appplant.cordova.plugin.localnotification.ClickReceiver} topActivity=ComponentInfo{edu.berkeley.eecs.emission/de.appplant.cordova.plugin.localnotification.ClickReceiver} origActivity=null realActivity=ComponentInfo{edu.berkeley.eecs.emission/de.appplant.cordova.plugin.localnotification.ClickReceiver} numActivities=1 lastActiveTime=4787963 supportsMultiWindow=true resizeMode=1 isResizeable=true minWidth=-1 minHeight=-1 defaultMinSize=220 token=WCT{android.window.IWindowContainerToken$Stub$Proxy@2a34e05} topActivityType=1 pictureInPictureParams=null shouldDockBigOverlays=false launchIntoPipHostTaskId=-1 lastParentTaskIdBeforePip=-1 displayCutoutSafeInsets=null topActivityInfo=ActivityInfo{e2bee5a de.appplant.cordova.plugin.localnotification.ClickReceiver} launchCookies=[] positionInParent=Point(0, 0) parentTaskId=-1 isFocused=false isVisible=false isVisibleRequested=false isSleeping=false topActivityInSizeCompat=false topActivityEligibleForLetterboxEducation= false topActivityLetterboxed= false isFromDoubleTap= false topActivityLetterboxVerticalPosition= -1 topActivityLetterboxHorizontalPosition= -1 topActivityLetterboxWidth=-1 topActivityLetterboxHeight=-1 locusId=null displayAreaFeatureId=1 cameraCompatControlState=hidden}, remoteTransition = RemoteTransition { remoteTransition = com.android.systemui.shared.system.RemoteAnimationRunnerCompat$1@ef0188b, appThread = null, debugName = SysUILaunch }, displayChange = null }
08-27 17:01:09.359   538  3443 I ActivityTaskManager: START u0 {flg=0x5000c000 cmp=edu.berkeley.eecs.emission/de.appplant.cordova.plugin.localnotification.ClickReceiver (has extras)} with LAUNCH_MULTIPLE from uid 10192 (realCallingUid=10163) (BAL_ALLOW_PENDING_INTENT) result code=0
08-27 17:01:09.395   538   558 V WindowManager: Sent Transition #102 createdAt=08-27 17:01:09.351 via request=TransitionRequestInfo { type = OPEN, triggerTask = TaskInfo{userId=0 taskId=29 displayId=0 isRunning=true baseIntent=Intent { flg=0x5000c000 cmp=edu.berkeley.eecs.emission/de.appplant.cordova.plugin.localnotification.ClickReceiver } baseActivity=ComponentInfo{edu.berkeley.eecs.emission/de.appplant.cordova.plugin.localnotification.ClickReceiver} topActivity=ComponentInfo{edu.berkeley.eecs.emission/de.appplant.cordova.plugin.localnotification.ClickReceiver} origActivity=null realActivity=ComponentInfo{edu.berkeley.eecs.emission/de.appplant.cordova.plugin.localnotification.ClickReceiver} numActivities=1 lastActiveTime=4787963 supportsMultiWindow=true resizeMode=1 isResizeable=true minWidth=-1 minHeight=-1 defaultMinSize=220 token=WCT{RemoteToken{46e322d Task{cbd08ac #29 type=standard A=10192:edu.berkeley.eecs.emission}}} topActivityType=1 pictureInPictureParams=null shouldDockBigOverlays=false launchIntoPipHostTaskId=-1 lastParentTaskIdBeforePip=-1 displayCutoutSafeInsets=null topActivityInfo=ActivityInfo{2034362 de.appplant.cordova.plugin.localnotification.ClickReceiver} launchCookies=[] positionInParent=Point(0, 0) parentTaskId=-1 isFocused=false isVisible=false isVisibleRequested=false isSleeping=false topActivityInSizeCompat=false topActivityEligibleForLetterboxEducation= false topActivityLetterboxed= false isFromDoubleTap= false topActivityLetterboxVerticalPosition= -1 topActivityLetterboxHorizontalPosition= -1 topActivityLetterboxWidth=-1 topActivityLetterboxHeight=-1 locusId=null displayAreaFeatureId=1 cameraCompatControlState=hidden}, remoteTransition = RemoteTransition { remoteTransition = android.window.IRemoteTransition$Stub$Proxy@9b7bcf3, appThread = null, debugName = SysUILaunch }, displayChange = null }
08-27 17:01:09.447   538  1542 D CoreBackPreview: Window{e079e5 u0 edu.berkeley.eecs.emission/de.appplant.cordova.plugin.localnotification.ClickReceiver}: Setting back callback OnBackInvokedCallbackInfo{mCallback=android.window.IOnBackInvokedCallback$Stub$Proxy@62bd76b, mPriority=0, mIsAnimationCallback=false}
```

And the javascript gets the callbacks for add/click

```
08-27 17:01:09.535 11959 11959 D CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.fireEvent("add",{"id":1724803257028,"title":"Dummy Title","text":"Dummy text","actions":"dummy-actions","trigger":{"at":1724803262028,"type":"calendar"},"alarmVolume":-1,"attachments":[],"autoLaunch":false,"autoClear":true,"clock":true,"defaults":0,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"resetDelay":5,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"timeoutAfter":null,"vibrate":false,"wakeup":true,"fullScreenIntent":false,"triggerInApp":false,"meta":{"plugin":"cordova-plugin-local-notification-12","version":"0.9-beta.5"}},{"event":"add","foreground":false,"queued":true,"notification":-1773595964}))
08-27 17:01:09.537 11959 11959 D CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.fireEvent("click",{"id":1724803257028,"title":"Dummy Title","text":"Dummy text","actions":"dummy-actions","trigger":{"at":1724803262028,"type":"calendar"},"alarmVolume":-1,"attachments":[],"autoLaunch":false,"autoClear":true,"clock":true,"defaults":0,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"resetDelay":5,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"timeoutAfter":null,"vibrate":false,"wakeup":true,"fullScreenIntent":false,"triggerInApp":false,"meta":{"plugin":"cordova-plugin-local-notification-12","version":"0.9-beta.5"}},{"event":"click","foreground":false,"queued":true,"notification":-1773595964}))
```

And add/clear

```
08-27 17:05:37.565 11959 11959 D CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.fireEvent("add",{"id":1724803537551,"title":"Dummy Title","text":"Dummy text","actions":"dummy-actions","trigger":{"at":1724803542551,"type":"calendar"},"alarmVolume":-1,"attachments":[],"autoLaunch":false,"autoClear":true,"clock":true,"defaults":0,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"resetDelay":5,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"timeoutAfter":null,"vibrate":false,"wakeup":true,"fullScreenIntent":false,"triggerInApp":false,"meta":{"plugin":"cordova-plugin-local-notification-12","version":"0.9-beta.5"}},{"event":"add","foreground":true,"queued":false,"notification":-1773315441}))
08-27 17:06:09.523 11959 11959 D CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.fireEvent("clear",{"id":1724803537551,"title":"Dummy Title","text":"Dummy text","actions":"dummy-actions","trigger":{"at":1724803542551,"type":"calendar"},"alarmVolume":-1,"attachments":[],"autoLaunch":false,"autoClear":true,"clock":true,"defaults":0,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"resetDelay":5,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"timeoutAfter":null,"vibrate":false,"wakeup":true,"fullScreenIntent":false,"triggerInApp":false,"meta":{"plugin":"cordova-plugin-local-notification-12","version":"0.9-beta.5"}},{"event":"clear","foreground":false,"queued":false,"notification":-1773315441}))
```

No crashes
  • Loading branch information
shankari committed Aug 28, 2024
1 parent 79f8d6d commit 2eec289
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/android/notification/util/LaunchUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ private static int getRandomCode() {
}

private static int getIntentFlags() {
int FLAG_MUTABLE = 33554432; // don't use pendingIntent.FLAG_MUTABLE, use numeric value instead to be able to compile api < 31
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (android.os.Build.VERSION.SDK_INT >= 31) {
flags |= FLAG_MUTABLE;
flags |= PendingIntent.FLAG_IMMUTABLE;
}
return flags;
}
Expand Down Expand Up @@ -67,4 +66,4 @@ public static void launchApp(Context context) {

context.startActivity(intent);
}
}
}

0 comments on commit 2eec289

Please sign in to comment.