QuickTileService: require SYSTEM_ALERT_WINDOW to start background activity
Due to buggy changes in Android 14, we now need to bother the user about enabling "draw over other apps" for the quick settings toggle to work when the app isn't already running. Link: https://issuetracker.google.com/issues/305035828 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
db7f70736f
commit
8390553850
@ -7,6 +7,9 @@
|
|||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||||
|
<uses-permission
|
||||||
|
android:name="android.permission.SYSTEM_ALERT_WINDOW"
|
||||||
|
android:minSdkVersion="34" />
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
android:maxSdkVersion="28"
|
android:maxSdkVersion="28"
|
||||||
|
@ -9,8 +9,10 @@ import android.content.Intent
|
|||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.drawable.Icon
|
import android.graphics.drawable.Icon
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import android.provider.Settings
|
||||||
import android.service.quicksettings.Tile
|
import android.service.quicksettings.Tile
|
||||||
import android.service.quicksettings.TileService
|
import android.service.quicksettings.TileService
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@ -55,7 +57,7 @@ class QuickTileService : TileService() {
|
|||||||
val intent = Intent(this, MainActivity::class.java)
|
val intent = Intent(this, MainActivity::class.java)
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||||
startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE))
|
startActivityAndCollapse(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE))
|
||||||
} else {
|
} else {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
startActivityAndCollapse(intent)
|
startActivityAndCollapse(intent)
|
||||||
@ -68,6 +70,12 @@ class QuickTileService : TileService() {
|
|||||||
tunnel.setStateAsync(Tunnel.State.TOGGLE)
|
tunnel.setStateAsync(Tunnel.State.TOGGLE)
|
||||||
updateTile()
|
updateTile()
|
||||||
} catch (_: Throwable) {
|
} catch (_: Throwable) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !Settings.canDrawOverlays(this@QuickTileService)) {
|
||||||
|
val permissionIntent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName"))
|
||||||
|
permissionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
startActivityAndCollapse(PendingIntent.getActivity(this@QuickTileService, 0, permissionIntent, PendingIntent.FLAG_IMMUTABLE))
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
val toggleIntent = Intent(this@QuickTileService, TunnelToggleActivity::class.java)
|
val toggleIntent = Intent(this@QuickTileService, TunnelToggleActivity::class.java)
|
||||||
toggleIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
toggleIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
startActivity(toggleIntent)
|
startActivity(toggleIntent)
|
||||||
|
Loading…
Reference in New Issue
Block a user