summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Charles Lombardo2023-05-29 03:16:04 -0400
committerGravatar bunnei2023-06-03 00:06:05 -0700
commit0f9c5b8d6a127258d8f4c21b6c3b12fe1d3998f3 (patch)
treec453802b68212d51ccbb6e502d742a06422e1f3b /src
parentandroid: Ensure keys are loaded before populating games list (diff)
downloadyuzu-0f9c5b8d6a127258d8f4c21b6c3b12fe1d3998f3.tar.gz
yuzu-0f9c5b8d6a127258d8f4c21b6c3b12fe1d3998f3.tar.xz
yuzu-0f9c5b8d6a127258d8f4c21b6c3b12fe1d3998f3.zip
android: Re-enable service notification
Diffstat (limited to 'src')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt22
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt15
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt4
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.kt12
4 files changed, 29 insertions, 24 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt
index ea4071ba7..37caa1b83 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt
@@ -31,18 +31,16 @@ import org.yuzu.yuzu_emu.features.settings.model.Settings
31import org.yuzu.yuzu_emu.fragments.EmulationFragment 31import org.yuzu.yuzu_emu.fragments.EmulationFragment
32import org.yuzu.yuzu_emu.model.Game 32import org.yuzu.yuzu_emu.model.Game
33import org.yuzu.yuzu_emu.utils.ControllerMappingHelper 33import org.yuzu.yuzu_emu.utils.ControllerMappingHelper
34import org.yuzu.yuzu_emu.utils.ForegroundService
34import org.yuzu.yuzu_emu.utils.InputHandler 35import org.yuzu.yuzu_emu.utils.InputHandler
35import org.yuzu.yuzu_emu.utils.NfcReader 36import org.yuzu.yuzu_emu.utils.NfcReader
36import org.yuzu.yuzu_emu.utils.SerializableHelper.parcelable 37import org.yuzu.yuzu_emu.utils.SerializableHelper.parcelable
37import org.yuzu.yuzu_emu.utils.ThemeHelper 38import org.yuzu.yuzu_emu.utils.ThemeHelper
38import kotlin.math.roundToInt 39import kotlin.math.roundToInt
39 40
40open class EmulationActivity : AppCompatActivity(), SensorEventListener { 41class EmulationActivity : AppCompatActivity(), SensorEventListener {
41 private var controllerMappingHelper: ControllerMappingHelper? = null 42 private var controllerMappingHelper: ControllerMappingHelper? = null
42 43
43 // TODO(bunnei): Disable notifications until we support app suspension.
44 //private Intent foregroundService;
45
46 var isActivityRecreated = false 44 var isActivityRecreated = false
47 private var menuVisible = false 45 private var menuVisible = false
48 private var emulationFragment: EmulationFragment? = null 46 private var emulationFragment: EmulationFragment? = null
@@ -57,8 +55,7 @@ open class EmulationActivity : AppCompatActivity(), SensorEventListener {
57 private lateinit var game: Game 55 private lateinit var game: Game
58 56
59 override fun onDestroy() { 57 override fun onDestroy() {
60 // TODO(bunnei): Disable notifications until we support app suspension. 58 stopForegroundService(this)
61 //stopService(foregroundService);
62 super.onDestroy() 59 super.onDestroy()
63 } 60 }
64 61
@@ -100,9 +97,8 @@ open class EmulationActivity : AppCompatActivity(), SensorEventListener {
100 inputHandler.initialize() 97 inputHandler.initialize()
101 98
102 // Start a foreground service to prevent the app from getting killed in the background 99 // Start a foreground service to prevent the app from getting killed in the background
103 // TODO(bunnei): Disable notifications until we support app suspension. 100 val startIntent = Intent(this, ForegroundService::class.java)
104 //foregroundService = new Intent(EmulationActivity.this, ForegroundService.class); 101 startForegroundService(startIntent)
105 //startForegroundService(foregroundService);
106 } 102 }
107 103
108 override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { 104 override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
@@ -324,7 +320,6 @@ open class EmulationActivity : AppCompatActivity(), SensorEventListener {
324 320
325 companion object { 321 companion object {
326 const val EXTRA_SELECTED_GAME = "SelectedGame" 322 const val EXTRA_SELECTED_GAME = "SelectedGame"
327 private const val EMULATION_RUNNING_NOTIFICATION = 0x1000
328 323
329 fun launch(activity: AppCompatActivity, game: Game) { 324 fun launch(activity: AppCompatActivity, game: Game) {
330 val launcher = Intent(activity, EmulationActivity::class.java) 325 val launcher = Intent(activity, EmulationActivity::class.java)
@@ -332,9 +327,10 @@ open class EmulationActivity : AppCompatActivity(), SensorEventListener {
332 activity.startActivity(launcher) 327 activity.startActivity(launcher)
333 } 328 }
334 329
335 fun tryDismissRunningNotification(activity: Activity?) { 330 fun stopForegroundService(activity: Activity) {
336 // TODO(bunnei): Disable notifications until we support app suspension. 331 val startIntent = Intent(activity, ForegroundService::class.java)
337 //NotificationManagerCompat.from(activity).cancel(EMULATION_RUNNING_NOTIFICATION); 332 startIntent.action = ForegroundService.ACTION_STOP
333 activity.startForegroundService(startIntent)
338 } 334 }
339 335
340 private fun areCoordinatesOutside(view: View?, x: Float, y: Float): Boolean { 336 private fun areCoordinatesOutside(view: View?, x: Float, y: Float): Boolean {
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
index a31414a0e..ce3f2639a 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
@@ -123,8 +123,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
123 } 123 }
124 124
125 R.id.menu_exit -> { 125 R.id.menu_exit -> {
126 requireActivity().finish()
127 emulationState.stop() 126 emulationState.stop()
127 requireActivity().finish()
128 true 128 true
129 } 129 }
130 130
@@ -364,7 +364,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
364 } 364 }
365 } 365 }
366 366
367 private class EmulationState(private val mGamePath: String?) { 367 private class EmulationState(private val gamePath: String) {
368 private var state: State 368 private var state: State
369 private var surface: Surface? = null 369 private var surface: Surface? = null
370 private var runWhenSurfaceIsValid = false 370 private var runWhenSurfaceIsValid = false
@@ -391,8 +391,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
391 fun stop() { 391 fun stop() {
392 if (state != State.STOPPED) { 392 if (state != State.STOPPED) {
393 Log.debug("[EmulationFragment] Stopping emulation.") 393 Log.debug("[EmulationFragment] Stopping emulation.")
394 state = State.STOPPED
395 NativeLibrary.stopEmulation() 394 NativeLibrary.stopEmulation()
395 state = State.STOPPED
396 } else { 396 } else {
397 Log.warning("[EmulationFragment] Stop called while already stopped.") 397 Log.warning("[EmulationFragment] Stop called while already stopped.")
398 } 398 }
@@ -402,12 +402,13 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
402 @Synchronized 402 @Synchronized
403 fun pause() { 403 fun pause() {
404 if (state != State.PAUSED) { 404 if (state != State.PAUSED) {
405 state = State.PAUSED
406 Log.debug("[EmulationFragment] Pausing emulation.") 405 Log.debug("[EmulationFragment] Pausing emulation.")
407 406
408 // Release the surface before pausing, since emulation has to be running for that. 407 // Release the surface before pausing, since emulation has to be running for that.
409 NativeLibrary.surfaceDestroyed() 408 NativeLibrary.surfaceDestroyed()
410 NativeLibrary.pauseEmulation() 409 NativeLibrary.pauseEmulation()
410
411 state = State.PAUSED
411 } else { 412 } else {
412 Log.warning("[EmulationFragment] Pause called while already paused.") 413 Log.warning("[EmulationFragment] Pause called while already paused.")
413 } 414 }
@@ -464,11 +465,11 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
464 when (state) { 465 when (state) {
465 State.STOPPED -> { 466 State.STOPPED -> {
466 NativeLibrary.surfaceChanged(surface) 467 NativeLibrary.surfaceChanged(surface)
467 val mEmulationThread = Thread({ 468 val emulationThread = Thread({
468 Log.debug("[EmulationFragment] Starting emulation thread.") 469 Log.debug("[EmulationFragment] Starting emulation thread.")
469 NativeLibrary.run(mGamePath) 470 NativeLibrary.run(gamePath)
470 }, "NativeEmulation") 471 }, "NativeEmulation")
471 mEmulationThread.start() 472 emulationThread.start()
472 } 473 }
473 474
474 State.PAUSED -> { 475 State.PAUSED -> {
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt
index 961b5b822..b1329db74 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt
@@ -119,7 +119,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
119 } 119 }
120 120
121 // Dismiss previous notifications (should not happen unless a crash occurred) 121 // Dismiss previous notifications (should not happen unless a crash occurred)
122 EmulationActivity.tryDismissRunningNotification(this) 122 EmulationActivity.stopForegroundService(this)
123 123
124 setInsets() 124 setInsets()
125 } 125 }
@@ -221,7 +221,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
221 } 221 }
222 222
223 override fun onDestroy() { 223 override fun onDestroy() {
224 EmulationActivity.tryDismissRunningNotification(this) 224 EmulationActivity.stopForegroundService(this)
225 super.onDestroy() 225 super.onDestroy()
226 } 226 }
227 227
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.kt
index 7e33ff044..626123966 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.kt
@@ -18,13 +18,16 @@ import org.yuzu.yuzu_emu.activities.EmulationActivity
18 */ 18 */
19class ForegroundService : Service() { 19class ForegroundService : Service() {
20 companion object { 20 companion object {
21 private const val EMULATION_RUNNING_NOTIFICATION = 0x1000 21 const val EMULATION_RUNNING_NOTIFICATION = 0x1000
22
23 const val ACTION_STOP = "stop"
22 } 24 }
23 25
24 private fun showRunningNotification() { 26 private fun showRunningNotification() {
25 // Intent is used to resume emulation if the notification is clicked 27 // Intent is used to resume emulation if the notification is clicked
26 val contentIntent = PendingIntent.getActivity( 28 val contentIntent = PendingIntent.getActivity(
27 this, 0, 29 this,
30 0,
28 Intent(this, EmulationActivity::class.java), 31 Intent(this, EmulationActivity::class.java),
29 PendingIntent.FLAG_IMMUTABLE 32 PendingIntent.FLAG_IMMUTABLE
30 ) 33 )
@@ -50,6 +53,11 @@ class ForegroundService : Service() {
50 } 53 }
51 54
52 override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { 55 override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
56 if (intent.action == ACTION_STOP) {
57 NotificationManagerCompat.from(this).cancel(EMULATION_RUNNING_NOTIFICATION)
58 stopForeground(STOP_FOREGROUND_REMOVE)
59 stopSelfResult(startId)
60 }
53 return START_STICKY 61 return START_STICKY
54 } 62 }
55 63