diff options
author | pacien | 2023-01-06 19:56:24 +0100 |
---|---|---|
committer | pacien | 2023-01-06 20:04:45 +0100 |
commit | a29c370ee7dff17798fdba8f3d54b9de62e64084 (patch) | |
tree | c370ad0d43e0f263345ed2e111b3a5176bf827a4 /app | |
parent | dd3fd370f63a20a77be2ddb1e8a1623d1618df45 (diff) | |
download | tincapp-a29c370ee7dff17798fdba8f3d54b9de62e64084.tar.gz |
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.
Diffstat (limited to 'app')
3 files changed, 41 insertions, 7 deletions
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 @@ | |||
1 | /* | 1 | /* |
2 | * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon | 2 | * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon |
3 | * Copyright (C) 2017-2020 Pacien TRAN-GIRARD | 3 | * Copyright (C) 2017-2023 Pacien TRAN-GIRARD |
4 | * | 4 | * |
5 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
@@ -18,10 +18,8 @@ | |||
18 | 18 | ||
19 | package org.pacien.tincapp.context | 19 | package org.pacien.tincapp.context |
20 | 20 | ||
21 | import android.app.Notification | ||
22 | import android.app.NotificationChannel | 21 | import android.app.NotificationChannel |
23 | import android.app.NotificationManager | 22 | import android.app.NotificationManager |
24 | import android.app.PendingIntent | ||
25 | import android.content.Context | 23 | import android.content.Context |
26 | import android.content.Intent | 24 | import android.content.Intent |
27 | import android.net.Uri | 25 | import android.net.Uri |
@@ -30,6 +28,7 @@ import androidx.annotation.RequiresApi | |||
30 | import androidx.core.app.NotificationCompat | 28 | import androidx.core.app.NotificationCompat |
31 | import androidx.core.app.NotificationManagerCompat | 29 | import androidx.core.app.NotificationManagerCompat |
32 | import org.pacien.tincapp.R | 30 | import org.pacien.tincapp.R |
31 | import org.pacien.tincapp.utils.PendingIntentUtils | ||
33 | 32 | ||
34 | /** | 33 | /** |
35 | * @author pacien | 34 | * @author pacien |
@@ -95,7 +94,7 @@ class AppNotificationManager(private val context: Context) { | |||
95 | 94 | ||
96 | private fun NotificationCompat.Builder.setManualLink(manualLink: String) = apply { | 95 | private fun NotificationCompat.Builder.setManualLink(manualLink: String) = apply { |
97 | val intent = Intent(Intent.ACTION_VIEW, Uri.parse(manualLink)) | 96 | val intent = Intent(Intent.ACTION_VIEW, Uri.parse(manualLink)) |
98 | val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0) | 97 | val pendingIntent = PendingIntentUtils.getActivity(context, 0, intent, 0) |
99 | addAction(R.drawable.ic_help_primary_24dp, context.getString(R.string.notification_error_action_open_manual), pendingIntent) | 98 | addAction(R.drawable.ic_help_primary_24dp, context.getString(R.string.notification_error_action_open_manual), pendingIntent) |
100 | } | 99 | } |
101 | } | 100 | } |
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 @@ | |||
1 | /* | 1 | /* |
2 | * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon | 2 | * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon |
3 | * Copyright (C) 2017-2020 Pacien TRAN-GIRARD | 3 | * Copyright (C) 2017-2023 Pacien TRAN-GIRARD |
4 | * | 4 | * |
5 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
@@ -18,7 +18,6 @@ | |||
18 | 18 | ||
19 | package org.pacien.tincapp.service | 19 | package org.pacien.tincapp.service |
20 | 20 | ||
21 | import android.app.PendingIntent | ||
22 | import android.app.Service | 21 | import android.app.Service |
23 | import android.content.Context | 22 | import android.content.Context |
24 | import android.content.Intent | 23 | import android.content.Intent |
@@ -39,6 +38,7 @@ import org.pacien.tincapp.activities.configure.ConfigureActivity | |||
39 | import org.pacien.tincapp.context.App | 38 | import org.pacien.tincapp.context.App |
40 | import org.pacien.tincapp.context.AppNotificationManager | 39 | import org.pacien.tincapp.context.AppNotificationManager |
41 | import org.pacien.tincapp.extensions.Java.defaultMessage | 40 | import org.pacien.tincapp.extensions.Java.defaultMessage |
41 | import org.pacien.tincapp.utils.PendingIntentUtils | ||
42 | import org.slf4j.LoggerFactory | 42 | import org.slf4j.LoggerFactory |
43 | import java.io.IOException | 43 | import java.io.IOException |
44 | 44 | ||
@@ -125,7 +125,7 @@ class ConfigurationAccessService : Service() { | |||
125 | .setContentTitle(resources.getString(R.string.notification_config_access_server_running_title)) | 125 | .setContentTitle(resources.getString(R.string.notification_config_access_server_running_title)) |
126 | .setContentText(resources.getString(R.string.notification_config_access_server_running_message)) | 126 | .setContentText(resources.getString(R.string.notification_config_access_server_running_message)) |
127 | .setContentIntent(Intent(this, ConfigureActivity::class.java).let { | 127 | .setContentIntent(Intent(this, ConfigureActivity::class.java).let { |
128 | PendingIntent.getActivity(this, 0, it, 0) | 128 | PendingIntentUtils.getActivity(this, 0, it, 0) |
129 | }) | 129 | }) |
130 | .build() | 130 | .build() |
131 | ) | 131 | ) |
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 @@ | |||
1 | /* | ||
2 | * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon | ||
3 | * Copyright (C) 2017-2023 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * This program is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation, either version 3 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | package org.pacien.tincapp.utils | ||
20 | |||
21 | import android.app.PendingIntent | ||
22 | import android.content.Context | ||
23 | import android.content.Intent | ||
24 | import android.os.Build | ||
25 | |||
26 | /** | ||
27 | * @author pacien | ||
28 | */ | ||
29 | object PendingIntentUtils { | ||
30 | fun getActivity(context: Context, requestCode: Int, intent: Intent, flags: Int): PendingIntent { | ||
31 | val extraFlags = | ||
32 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0 | ||
33 | return PendingIntent.getActivity(context, requestCode, intent, flags or extraFlags) | ||
34 | } | ||
35 | } | ||