0
0
Fork 0
mirror of https://github.com/YTVanced/VancedMicroG synced 2024-11-28 06:03:00 +00:00

Revert "Fix FC" and completely restore ForegroundServiceContext.java

This commit is contained in:
Oizaro 2020-09-19 21:28:42 +02:00
parent 95543f10a4
commit d25c9cf24a
2 changed files with 20 additions and 7 deletions

View file

@ -1,6 +1,9 @@
package org.microg.gms.common; package org.microg.gms.common;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service; import android.app.Service;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
@ -24,7 +27,7 @@ public class ForegroundServiceContext extends ContextWrapper {
@Override @Override
public ComponentName startService(Intent service) { 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."); Log.d(TAG, "Starting in foreground mode.");
service.putExtra(EXTRA_FOREGROUND, true); service.putExtra(EXTRA_FOREGROUND, true);
return super.startForegroundService(service); return super.startForegroundService(service);
@ -56,6 +59,21 @@ public class ForegroundServiceContext extends ContextWrapper {
public static void completeForegroundService(Service service, Intent intent, String tag) { 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) { if (intent != null && intent.getBooleanExtra(EXTRA_FOREGROUND, false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log.d(tag, "Started in foreground mode."); 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();
}
} }

View file

@ -17,9 +17,6 @@
package org.microg.gms.gcm; package org.microg.gms.gcm;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.ComponentName; import android.content.ComponentName;
@ -41,10 +38,8 @@ import android.os.SystemClock;
import android.os.UserHandle; import android.os.UserHandle;
import android.util.Log; import android.util.Log;
import androidx.core.app.NotificationCompat;
import androidx.legacy.content.WakefulBroadcastReceiver; import androidx.legacy.content.WakefulBroadcastReceiver;
import com.mgoogle.android.gms.R;
import com.squareup.wire.Message; import com.squareup.wire.Message;
import org.microg.gms.checkin.LastCheckinInfo; import org.microg.gms.checkin.LastCheckinInfo;