From a29c370ee7dff17798fdba8f3d54b9de62e64084 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 6 Jan 2023 19:56:24 +0100 Subject: fix app crash due to missing intent flag for android API >=31 This was causing a crash when connecting or enabling the internal FTP server or opening manual links. --- .../tincapp/context/AppNotificationManager.kt | 7 ++--- .../tincapp/service/ConfigurationAccessService.kt | 6 ++-- .../org/pacien/tincapp/utils/PendingIntentUtils.kt | 35 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/org/pacien/tincapp/utils/PendingIntentUtils.kt diff --git a/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt b/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt index 9d731a5..5b01a54 100644 --- a/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt +++ b/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt @@ -1,6 +1,6 @@ /* * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon - * Copyright (C) 2017-2020 Pacien TRAN-GIRARD + * Copyright (C) 2017-2023 Pacien TRAN-GIRARD * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,10 +18,8 @@ package org.pacien.tincapp.context -import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager -import android.app.PendingIntent import android.content.Context import android.content.Intent import android.net.Uri @@ -30,6 +28,7 @@ import androidx.annotation.RequiresApi import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import org.pacien.tincapp.R +import org.pacien.tincapp.utils.PendingIntentUtils /** * @author pacien @@ -95,7 +94,7 @@ class AppNotificationManager(private val context: Context) { private fun NotificationCompat.Builder.setManualLink(manualLink: String) = apply { val intent = Intent(Intent.ACTION_VIEW, Uri.parse(manualLink)) - val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0) + val pendingIntent = PendingIntentUtils.getActivity(context, 0, intent, 0) addAction(R.drawable.ic_help_primary_24dp, context.getString(R.string.notification_error_action_open_manual), pendingIntent) } } diff --git a/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt b/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt index 1708243..916f19d 100644 --- a/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt +++ b/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt @@ -1,6 +1,6 @@ /* * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon - * Copyright (C) 2017-2020 Pacien TRAN-GIRARD + * Copyright (C) 2017-2023 Pacien TRAN-GIRARD * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,6 @@ package org.pacien.tincapp.service -import android.app.PendingIntent import android.app.Service import android.content.Context import android.content.Intent @@ -39,6 +38,7 @@ import org.pacien.tincapp.activities.configure.ConfigureActivity import org.pacien.tincapp.context.App import org.pacien.tincapp.context.AppNotificationManager import org.pacien.tincapp.extensions.Java.defaultMessage +import org.pacien.tincapp.utils.PendingIntentUtils import org.slf4j.LoggerFactory import java.io.IOException @@ -125,7 +125,7 @@ class ConfigurationAccessService : Service() { .setContentTitle(resources.getString(R.string.notification_config_access_server_running_title)) .setContentText(resources.getString(R.string.notification_config_access_server_running_message)) .setContentIntent(Intent(this, ConfigureActivity::class.java).let { - PendingIntent.getActivity(this, 0, it, 0) + PendingIntentUtils.getActivity(this, 0, it, 0) }) .build() ) diff --git a/app/src/main/java/org/pacien/tincapp/utils/PendingIntentUtils.kt b/app/src/main/java/org/pacien/tincapp/utils/PendingIntentUtils.kt new file mode 100644 index 0000000..f2a6abe --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/utils/PendingIntentUtils.kt @@ -0,0 +1,35 @@ +/* + * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon + * Copyright (C) 2017-2023 Pacien TRAN-GIRARD + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.pacien.tincapp.utils + +import android.app.PendingIntent +import android.content.Context +import android.content.Intent +import android.os.Build + +/** + * @author pacien + */ +object PendingIntentUtils { + fun getActivity(context: Context, requestCode: Int, intent: Intent, flags: Int): PendingIntent { + val extraFlags = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0 + return PendingIntent.getActivity(context, requestCode, intent, flags or extraFlags) + } +} -- cgit v1.2.3