From 00a8e835407ec432e3d65a9052c660cf1ef291c8 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Tue, 1 Dec 2020 18:26:10 +0100 Subject: [PATCH] Also show service notification when app is in foreground. Useful when embedding microG --- .../gms/common/ForegroundServiceContext.java | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/play-services-base-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java b/play-services-base-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java index 4282774b..9ff1b5d2 100644 --- a/play-services-base-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java +++ b/play-services-base-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java @@ -1,6 +1,5 @@ package org.microg.gms.common; -import android.app.ActivityManager; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -15,8 +14,6 @@ import android.util.Log; import androidx.annotation.RequiresApi; -import java.util.List; - public class ForegroundServiceContext extends ContextWrapper { private static final String TAG = "ForegroundService"; public static final String EXTRA_FOREGROUND = "foreground"; @@ -27,7 +24,7 @@ public class ForegroundServiceContext extends ContextWrapper { @Override public ComponentName startService(Intent service) { - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isIgnoringBatteryOptimizations() && !isAppOnForeground()) { + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isIgnoringBatteryOptimizations()) { Log.d(TAG, "Starting in foreground mode."); service.putExtra(EXTRA_FOREGROUND, true); return super.startForegroundService(service); @@ -41,21 +38,6 @@ public class ForegroundServiceContext extends ContextWrapper { return powerManager.isIgnoringBatteryOptimizations(getPackageName()); } - private boolean isAppOnForeground() { - ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); - List appProcesses = activityManager.getRunningAppProcesses(); - if (appProcesses == null) { - return false; - } - final String packageName = getPackageName(); - for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { - if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals(packageName)) { - return true; - } - } - return false; - } - public static void completeForegroundService(Service service, Intent intent, String tag) { if (intent != null && intent.getBooleanExtra(EXTRA_FOREGROUND, false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Log.d(tag, "Started in foreground mode."); @@ -73,7 +55,7 @@ public class ForegroundServiceContext extends ContextWrapper { return new Notification.Builder(context, channel.getId()) .setOngoing(true) .setContentTitle("Running in background") - //.setSmallIcon(R.drawable.ic_cloud_bell) + .setContentText("microG " + context.getClass().getSimpleName() + " is running in background.") .build(); } }