Remove permission FOREGROUND_SERVICE

This commit is contained in:
Thomas 2025-04-01 14:57:32 +02:00
parent fed33cf600
commit c69cf6e295
2 changed files with 3 additions and 44 deletions

View file

@ -512,9 +512,9 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
}
private void startInForeground() {
Intent notificationIntent = new Intent(this, RetrieveInfoService.class);
Intent retrieveInfoServiceIntent = new Intent(this, RetrieveInfoService.class);
try {
startService(notificationIntent);
startService(retrieveInfoServiceIntent);
} catch (Exception ignored) {
}
}

View file

@ -16,28 +16,19 @@ package app.fedilab.android.peertube.services;
import static app.fedilab.android.peertube.helper.Helper.peertubeInformation;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ServiceInfo;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import java.util.LinkedHashMap;
import java.util.Objects;
import app.fedilab.android.R;
import app.fedilab.android.peertube.client.RetrofitPeertubeAPI;
import app.fedilab.android.peertube.client.entities.PeertubeInformation;
import app.fedilab.android.peertube.helper.EmojiHelper;
@ -46,7 +37,6 @@ import app.fedilab.android.peertube.helper.NetworkStateReceiver;
public class RetrieveInfoService extends Service implements NetworkStateReceiver.NetworkStateReceiverListener {
static String NOTIFICATION_CHANNEL_ID = "update_info_peertube";
private NetworkStateReceiver networkStateReceiver;
@ -55,36 +45,6 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
networkStateReceiver = new NetworkStateReceiver();
networkStateReceiver.addListener(this);
ContextCompat.registerReceiver(RetrieveInfoService.this, networkStateReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
getString(R.string.notification_channel_name),
NotificationManager.IMPORTANCE_DEFAULT);
channel.setSound(null, null);
((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel);
Notification notification = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.notification_channel_name))
.setAutoCancel(true).build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(1, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC);
} else {
startForeground(1, notification);
}
} else {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setContentTitle(getString(R.string.app_name))
.setDefaults(Notification.DEFAULT_ALL)
.setContentText(getString(R.string.notification_channel_name))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true);
Notification notification = builder.build();
startForeground(1, notification);
}
}
@ -140,7 +100,7 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
@Override
public void run() {
EmojiHelper.fillMapEmoji(getApplicationContext());
if (peertubeInformation == null || peertubeInformation.getCategories() == null || peertubeInformation.getCategories().size() == 0) {
if (peertubeInformation == null || peertubeInformation.getCategories() == null || peertubeInformation.getCategories().isEmpty()) {
peertubeInformation = new PeertubeInformation();
peertubeInformation.setCategories(new LinkedHashMap<>());
peertubeInformation.setLanguages(new LinkedHashMap<>());
@ -150,7 +110,6 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
peertubeInformation.setTranslations(new LinkedHashMap<>());
peertubeInformation = new RetrofitPeertubeAPI(RetrieveInfoService.this).getPeertubeInformation();
}
stopForeground(true);
}
};
thread.start();