Foreground Permission Reset
continuous-integration/drone/pr Build is passing Details

As of Android 13 we need to request a permission to stay in the background
https://developer.android.com/develop/background-work/background-tasks/persistent/how-to/long-running
This commit is contained in:
Sarah Jamie Lewis 2024-02-23 11:18:43 -08:00
parent 5626e6ed90
commit 0ea595692f
Signed by: sarah
GPG Key ID: F27FD21A270837EF
2 changed files with 11 additions and 3 deletions

View File

@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="im.cwtch.flwtch">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
@ -38,14 +38,21 @@
android:name="flutterEmbedding"
android:value="2" />
<!--Needed to run in background (lol)-->
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
tools:node="merge" />
</application>
<!--Needed to access Tor socket-->
<uses-permission android:name="android.permission.INTERNET" />
<!--Needed to run in background (lol)-->
<!-- Needed for running in the background -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- As of Android 13 this permission is required -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<!-- Ability to ask user to exempt app from power management (which can kill it more frequently especially on some devices.
Allows app to use ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS -->

View File

@ -11,6 +11,7 @@ import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.util.Log
import android.content.pm.ServiceInfo
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.localbroadcastmanager.content.LocalBroadcastManager
@ -292,7 +293,7 @@ class FlwtchWorker(context: Context, parameters: WorkerParameters) :
.addAction(android.R.drawable.ic_delete, cancel, PendingIntent.getActivity(applicationContext, 2, cancelIntent, flags))
.build()
return ForegroundInfo(101, notification)
return ForegroundInfo(101, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
}
@RequiresApi(Build.VERSION_CODES.O)