mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-03 00:00:24 -04:00
android: Add workaround for a bug preventing background service starts from TileService
When targeting Android 14, we get a "Background activity launch blocked!" exception when trying to start the connection in the background (closing the drawer works). Which is apparently a bug: https://issuetracker.google.com/issues/305035828 The workaround here is kinda ugly. In particular, because it's not possible anymore since a few versions to open a dialog that allows users to directly grant the required permission to the app. We can only open the generic settings dialog where users have to search for the app and grant the permission themselves (we could add a dialog with an explanation similar to the one for the power whitelist if necessary). Hopefully this gets fixed at some point (the current beta of Android 15 still has the same bug, though).
This commit is contained in:
parent
3286f75ffe
commit
51f746161d
@ -26,6 +26,7 @@
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<!-- necessary to allow users to select ex-/included apps and EAP-TNC -->
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||
tools:ignore="QueryAllPackagesPermission" />
|
||||
|
@ -28,6 +28,7 @@ import android.content.SharedPreferences;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.provider.Settings;
|
||||
import android.service.quicksettings.Tile;
|
||||
import android.service.quicksettings.TileService;
|
||||
|
||||
@ -191,6 +192,15 @@ public class VpnTileService extends TileService implements VpnStateService.VpnSt
|
||||
}
|
||||
else
|
||||
{
|
||||
/* a bug in Android 14+ requires us to request this permission in
|
||||
* order to start the activity from this "background" service */
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !Settings.canDrawOverlays(this))
|
||||
{
|
||||
Intent permIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
||||
permIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivityAndCollapse(PendingIntent.getActivity(this, 0, permIntent, PendingIntent.FLAG_IMMUTABLE));
|
||||
return;
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user