summaryrefslogtreecommitdiff
path: root/src/android/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/app')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.java63
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.kt56
2 files changed, 56 insertions, 63 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.java
deleted file mode 100644
index 8834c7bc5..000000000
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.java
+++ /dev/null
@@ -1,63 +0,0 @@
1/**
2 * Copyright 2014 Dolphin Emulator Project
3 * Licensed under GPLv2+
4 * Refer to the license.txt file included.
5 */
6
7package org.yuzu.yuzu_emu.utils;
8
9import android.app.PendingIntent;
10import android.app.Service;
11import android.content.Intent;
12import android.os.IBinder;
13
14import androidx.core.app.NotificationCompat;
15import androidx.core.app.NotificationManagerCompat;
16
17import org.yuzu.yuzu_emu.R;
18import org.yuzu.yuzu_emu.activities.EmulationActivity;
19
20/**
21 * A service that shows a permanent notification in the background to avoid the app getting
22 * cleared from memory by the system.
23 */
24public class ForegroundService extends Service {
25 private static final int EMULATION_RUNNING_NOTIFICATION = 0x1000;
26
27 private void showRunningNotification() {
28 // Intent is used to resume emulation if the notification is clicked
29 PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
30 new Intent(this, EmulationActivity.class), PendingIntent.FLAG_IMMUTABLE);
31
32 NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.app_notification_channel_id))
33 .setSmallIcon(R.drawable.ic_stat_notification_logo)
34 .setContentTitle(getString(R.string.app_name))
35 .setContentText(getString(R.string.app_notification_running))
36 .setPriority(NotificationCompat.PRIORITY_LOW)
37 .setOngoing(true)
38 .setVibrate(null)
39 .setSound(null)
40 .setContentIntent(contentIntent);
41 startForeground(EMULATION_RUNNING_NOTIFICATION, builder.build());
42 }
43
44 @Override
45 public IBinder onBind(Intent intent) {
46 return null;
47 }
48
49 @Override
50 public void onCreate() {
51 showRunningNotification();
52 }
53
54 @Override
55 public int onStartCommand(Intent intent, int flags, int startId) {
56 return START_STICKY;
57 }
58
59 @Override
60 public void onDestroy() {
61 NotificationManagerCompat.from(this).cancel(EMULATION_RUNNING_NOTIFICATION);
62 }
63}
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
new file mode 100644
index 000000000..238ed54d3
--- /dev/null
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/ForegroundService.kt
@@ -0,0 +1,56 @@
1package org.yuzu.yuzu_emu.utils
2
3import android.app.PendingIntent
4import android.app.Service
5import android.content.Intent
6import android.os.IBinder
7import androidx.core.app.NotificationCompat
8import androidx.core.app.NotificationManagerCompat
9import org.yuzu.yuzu_emu.R
10import org.yuzu.yuzu_emu.activities.EmulationActivity
11
12/**
13 * A service that shows a permanent notification in the background to avoid the app getting
14 * cleared from memory by the system.
15 */
16class ForegroundService : Service() {
17 companion object {
18 private const val EMULATION_RUNNING_NOTIFICATION = 0x1000
19 }
20
21 private fun showRunningNotification() {
22 // Intent is used to resume emulation if the notification is clicked
23 val contentIntent = PendingIntent.getActivity(
24 this, 0,
25 Intent(this, EmulationActivity::class.java),
26 PendingIntent.FLAG_IMMUTABLE
27 )
28 val builder =
29 NotificationCompat.Builder(this, getString(R.string.app_notification_channel_id))
30 .setSmallIcon(R.drawable.ic_stat_notification_logo)
31 .setContentTitle(getString(R.string.app_name))
32 .setContentText(getString(R.string.app_notification_running))
33 .setPriority(NotificationCompat.PRIORITY_LOW)
34 .setOngoing(true)
35 .setVibrate(null)
36 .setSound(null)
37 .setContentIntent(contentIntent)
38 startForeground(EMULATION_RUNNING_NOTIFICATION, builder.build())
39 }
40
41 override fun onBind(intent: Intent): IBinder? {
42 return null
43 }
44
45 override fun onCreate() {
46 showRunningNotification()
47 }
48
49 override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
50 return START_STICKY
51 }
52
53 override fun onDestroy() {
54 NotificationManagerCompat.from(this).cancel(EMULATION_RUNNING_NOTIFICATION)
55 }
56}