-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround trampoline exception by using an activity instead of a bro…
…adcast receiver. Closes #1191
- Loading branch information
Showing
10 changed files
with
199 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
acra-notification/src/main/java/org/acra/receiver/NotificationActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2023 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.acra.receiver | ||
|
||
import android.app.Activity | ||
|
||
class NotificationActivity : Activity() { | ||
override fun onStart() { | ||
super.onStart() | ||
handleNotificationIntent(this, intent) | ||
finish() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
acra-notification/src/main/java/org/acra/receiver/handleNotificationIntent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (c) 2023 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.acra.receiver | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.core.app.RemoteInput | ||
import org.acra.ReportField | ||
import org.acra.config.CoreConfiguration | ||
import org.acra.file.BulkReportDeleter | ||
import org.acra.file.CrashReportPersister | ||
import org.acra.interaction.NotificationInteraction | ||
import org.acra.log.debug | ||
import org.acra.log.warn | ||
import org.acra.scheduler.SchedulerStarter | ||
import org.acra.sender.LegacySenderService | ||
import org.acra.util.SystemServices | ||
import org.acra.util.kGetSerializableExtra | ||
import org.json.JSONException | ||
import java.io.File | ||
import java.io.IOException | ||
|
||
fun handleNotificationIntent(context: Context, intent: Intent) { | ||
try { | ||
debug { "NotificationBroadcastReceiver called with $intent" } | ||
val notificationManager = SystemServices.getNotificationManager(context) | ||
notificationManager.cancel(NotificationInteraction.NOTIFICATION_ID) | ||
debug { "notification intent action = ${intent.action}" } | ||
if (intent.action != null) { | ||
when (intent.action) { | ||
NotificationInteraction.INTENT_ACTION_SEND -> { | ||
val reportFile = intent.kGetSerializableExtra<File>(NotificationInteraction.EXTRA_REPORT_FILE) | ||
val configObject = intent.kGetSerializableExtra<CoreConfiguration>(LegacySenderService.EXTRA_ACRA_CONFIG) | ||
if (configObject != null && reportFile != null) { | ||
//Grab user comment from notification intent | ||
val remoteInput = RemoteInput.getResultsFromIntent(intent) | ||
if (remoteInput != null) { | ||
val comment = remoteInput.getCharSequence(NotificationInteraction.KEY_COMMENT) | ||
if (comment != null && "" != comment.toString()) { | ||
val persister = CrashReportPersister() | ||
try { | ||
debug { "Add user comment to $reportFile" } | ||
val crashData = persister.load(reportFile) | ||
crashData.put(ReportField.USER_COMMENT, comment.toString()) | ||
persister.store(crashData, reportFile) | ||
} catch (e: IOException) { | ||
warn(e) { "User comment not added: " } | ||
} catch (e: JSONException) { | ||
warn(e) { "User comment not added: " } | ||
} | ||
} | ||
} | ||
SchedulerStarter(context, configObject).scheduleReports(reportFile, false) | ||
} | ||
} | ||
|
||
NotificationInteraction.INTENT_ACTION_DISCARD -> { | ||
debug { "Discarding reports" } | ||
BulkReportDeleter(context).deleteReports(false, 0) | ||
} | ||
} | ||
} | ||
} catch (t: Exception) { | ||
org.acra.log.error(t) { "Failed to handle notification action" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (c) 2019 | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<resources> | ||
<bool name="acra_enable_notification_activity">true</bool> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (c) 2019 | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<resources> | ||
<bool name="acra_enable_notification_activity">false</bool> | ||
</resources> |