From d25c9cf24a066b3edffd0e845e04f35a414eeb96 Mon Sep 17 00:00:00 2001 From: Oizaro <45825534+Oizaro@users.noreply.github.com> Date: Sat, 19 Sep 2020 21:28:42 +0200 Subject: [PATCH] Revert "Fix FC" and completely restore ForegroundServiceContext.java --- .../gms/common/ForegroundServiceContext.java | 22 +++++++++++++++++-- .../java/org/microg/gms/gcm/McsService.java | 5 ----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/play-services-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java b/play-services-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java index e18e7855..12b208dd 100644 --- a/play-services-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java +++ b/play-services-core/src/main/java/org/microg/gms/common/ForegroundServiceContext.java @@ -1,6 +1,9 @@ package org.microg.gms.common; import android.app.ActivityManager; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; import android.app.Service; import android.content.ComponentName; import android.content.Context; @@ -24,7 +27,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() && !isAppOnForeground()) { Log.d(TAG, "Starting in foreground mode."); service.putExtra(EXTRA_FOREGROUND, true); return super.startForegroundService(service); @@ -56,6 +59,21 @@ public class ForegroundServiceContext extends ContextWrapper { 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."); + service.startForeground(tag.hashCode(), buildForegroundNotification(service)); } } -} + + @RequiresApi(api = Build.VERSION_CODES.O) + private static Notification buildForegroundNotification(Context context) { + NotificationChannel channel = new NotificationChannel("foreground-service", "Foreground Service", NotificationManager.IMPORTANCE_NONE); + channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET); + channel.setShowBadge(false); + channel.setVibrationPattern(new long[0]); + context.getSystemService(NotificationManager.class).createNotificationChannel(channel); + return new Notification.Builder(context, channel.getId()) + .setOngoing(true) + .setContentTitle("Running in background") + //.setSmallIcon(R.drawable.ic_cloud_bell) + .build(); + } +} \ No newline at end of file diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java index 8142adfd..309e171f 100644 --- a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java +++ b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java @@ -17,9 +17,6 @@ package org.microg.gms.gcm; import android.app.AlarmManager; -import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.ComponentName; @@ -41,10 +38,8 @@ import android.os.SystemClock; import android.os.UserHandle; import android.util.Log; -import androidx.core.app.NotificationCompat; import androidx.legacy.content.WakefulBroadcastReceiver; -import com.mgoogle.android.gms.R; import com.squareup.wire.Message; import org.microg.gms.checkin.LastCheckinInfo;