]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Use PendingIntent-version of startActivityAndCollapse()
authorTobias Brunner <tobias@strongswan.org>
Mon, 5 Aug 2024 08:47:10 +0000 (10:47 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 6 Aug 2024 16:01:54 +0000 (18:01 +0200)
The other version has been deprecated and throws an exception when
targeting Android 14+.

src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnTileService.java

index c49f4ba75e5e04814494b31dc90f35ea961a3a59..ac8c49ade991764369189767745a001858c08c99 100644 (file)
@@ -16,7 +16,9 @@
 
 package org.strongswan.android.ui;
 
+import android.annotation.SuppressLint;
 import android.annotation.TargetApi;
+import android.app.PendingIntent;
 import android.app.Service;
 import android.content.ComponentName;
 import android.content.Context;
@@ -127,6 +129,7 @@ public class VpnTileService extends TileService implements VpnStateService.VpnSt
                return mDataSource != null ? mDataSource.getVpnProfile(uuid) : null;
        }
 
+       @SuppressLint("StartActivityAndCollapseDeprecated")
        @Override
        public void onClick()
        {
@@ -177,7 +180,14 @@ public class VpnTileService extends TileService implements VpnStateService.VpnSt
                                if (profile.getVpnType().has(VpnType.VpnTypeFeature.USER_PASS) &&
                                        profile.getPassword() == null)
                                {       /* the user will have to enter the password, so collapse the drawer */
-                                       startActivityAndCollapse(intent);
+                                       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
+                                       {
+                                               startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE));
+                                       }
+                                       else
+                                       {
+                                               startActivityAndCollapse(intent);
+                                       }
                                }
                                else
                                {
@@ -188,7 +198,14 @@ public class VpnTileService extends TileService implements VpnStateService.VpnSt
                }
                Intent intent = new Intent(this, MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-               startActivityAndCollapse(intent);
+               if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
+               {
+                       startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE));
+               }
+               else
+               {
+                       startActivityAndCollapse(intent);
+               }
        }
 
        @Override