android: Removed foreground service leftovers

This commit is contained in:
OpenSauce04 2024-08-16 23:33:39 +01:00
parent dee80dab5e
commit b615d92541
4 changed files with 0 additions and 88 deletions

View File

@ -28,8 +28,6 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application <application
@ -80,10 +78,6 @@
</activity> </activity>
<service android:name="io.github.lime3ds.android.utils.ForegroundService" android:foregroundServiceType="specialUse">
<property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE" android:value="Keep emulation running in background"/>
</service>
<activity <activity
android:name="io.github.lime3ds.android.features.cheats.ui.CheatsActivity" android:name="io.github.lime3ds.android.features.cheats.ui.CheatsActivity"
android:exported="false" android:exported="false"

View File

@ -40,7 +40,6 @@ import io.github.lime3ds.android.fragments.EmulationFragment
import io.github.lime3ds.android.fragments.MessageDialogFragment import io.github.lime3ds.android.fragments.MessageDialogFragment
import io.github.lime3ds.android.utils.ControllerMappingHelper import io.github.lime3ds.android.utils.ControllerMappingHelper
import io.github.lime3ds.android.utils.FileBrowserHelper import io.github.lime3ds.android.utils.FileBrowserHelper
import io.github.lime3ds.android.utils.ForegroundService
import io.github.lime3ds.android.utils.EmulationLifecycleUtil import io.github.lime3ds.android.utils.EmulationLifecycleUtil
import io.github.lime3ds.android.utils.EmulationMenuSettings import io.github.lime3ds.android.utils.EmulationMenuSettings
import io.github.lime3ds.android.utils.ThemeUtil import io.github.lime3ds.android.utils.ThemeUtil
@ -49,7 +48,6 @@ import io.github.lime3ds.android.viewmodel.EmulationViewModel
class EmulationActivity : AppCompatActivity() { class EmulationActivity : AppCompatActivity() {
private val preferences: SharedPreferences private val preferences: SharedPreferences
get() = PreferenceManager.getDefaultSharedPreferences(LimeApplication.appContext) get() = PreferenceManager.getDefaultSharedPreferences(LimeApplication.appContext)
private var foregroundService: Intent? = null
var isActivityRecreated = false var isActivityRecreated = false
private val emulationViewModel: EmulationViewModel by viewModels() private val emulationViewModel: EmulationViewModel by viewModels()
private val settingsViewModel: SettingsViewModel by viewModels() private val settingsViewModel: SettingsViewModel by viewModels()
@ -485,11 +483,5 @@ class EmulationActivity : AppCompatActivity() {
fun isRunning(): Boolean { fun isRunning(): Boolean {
return instance?.isEmulationRunning ?: false return instance?.isEmulationRunning ?: false
} }
fun stopForegroundService(activity: Activity) {
val startIntent = Intent(activity, ForegroundService::class.java)
startIntent.action = ForegroundService.ACTION_STOP
activity.startForegroundService(startIntent)
}
} }
} }

View File

@ -156,9 +156,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
} }
} }
// Dismiss previous notifications (should not happen unless a crash occurred)
EmulationActivity.stopForegroundService(this)
setInsets() setInsets()
} }
@ -170,7 +167,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
} }
override fun onDestroy() { override fun onDestroy() {
EmulationActivity.stopForegroundService(this)
super.onDestroy() super.onDestroy()
} }

View File

@ -1,70 +0,0 @@
// Copyright 2023 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
package io.github.lime3ds.android.utils
import android.app.PendingIntent
import android.app.Service
import android.content.Intent
import android.os.IBinder
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import io.github.lime3ds.android.R
import io.github.lime3ds.android.activities.EmulationActivity
/**
* A service that shows a permanent notification in the background to avoid the app getting
* cleared from memory by the system.
*/
class ForegroundService : Service() {
companion object {
const val EMULATION_RUNNING_NOTIFICATION = 0x1000
const val ACTION_STOP = "stop"
}
private fun showRunningNotification() {
// Intent is used to resume emulation if the notification is clicked
val contentIntent = PendingIntent.getActivity(
this,
0,
Intent(this, EmulationActivity::class.java),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val builder =
NotificationCompat.Builder(this, getString(R.string.app_notification_channel_id))
.setSmallIcon(R.drawable.ic_stat_notification_logo)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.app_notification_running))
.setPriority(NotificationCompat.PRIORITY_LOW)
.setOngoing(true)
.setVibrate(null)
.setSound(null)
.setContentIntent(contentIntent)
startForeground(EMULATION_RUNNING_NOTIFICATION, builder.build())
}
override fun onBind(intent: Intent): IBinder? {
return null
}
override fun onCreate() {
showRunningNotification()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (intent == null) {
return START_NOT_STICKY
}
if (intent.action == ACTION_STOP) {
NotificationManagerCompat.from(this).cancel(EMULATION_RUNNING_NOTIFICATION)
stopForeground(STOP_FOREGROUND_REMOVE)
stopSelfResult(startId)
}
return START_STICKY
}
override fun onDestroy() =
NotificationManagerCompat.from(this).cancel(EMULATION_RUNNING_NOTIFICATION)
}