导航菜单

页面标题

页面副标题

Delta Chat v1.58.3 - KeepAliveService.java 源代码

正在查看: Delta Chat v1.58.3 应用的 KeepAliveService.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package org.thoughtcrime.securesms.connect;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import org.thoughtcrime.securesms.ConversationListActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.notifications.NotificationCenter;
import org.thoughtcrime.securesms.util.IntentUtils;
import org.thoughtcrime.securesms.util.Prefs;
import org.thoughtcrime.securesms.util.ViewUtil$$ExternalSyntheticApiModelOutline0;

public class KeepAliveService extends Service {
    private static final String TAG = "KeepAliveService";
    private static boolean ch_created = false;
    static KeepAliveService s_this;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    public static void maybeStartSelf(Context context) {
        if (Prefs.reliableService(context)) {
            startSelf(context);
        }
    }

    public static void startSelf(Context context) {
        try {
            ContextCompat.startForegroundService(context, new Intent(context, (Class<?>) KeepAliveService.class));
        } catch (Exception e) {
            Log.i(TAG, "Error calling ContextCompat.startForegroundService()", e);
        }
    }

    @Override
    public void onCreate() {
        Log.i("DeltaChat", "*** KeepAliveService.onCreate()");
        s_this = this;
        try {
            stopForeground(true);
            startForeground(1, createNotification());
        } catch (Exception e) {
            Log.i(TAG, "Error in onCreate()", e);
        }
    }

    @Override
    public int onStartCommand(Intent intent, int i, int i2) {
        Log.i("DeltaChat", "*** KeepAliveService.onStartCommand()");
        return 1;
    }

    @Override
    public void onDestroy() {
        Log.i("DeltaChat", "*** KeepAliveService.onDestroy()");
    }

    public static KeepAliveService getInstance() {
        return s_this;
    }

    private Notification createNotification() {
        PendingIntent activity = PendingIntent.getActivity(this, 0, new Intent(this, (Class<?>) ConversationListActivity.class), 134217728 | IntentUtils.FLAG_MUTABLE());
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentTitle(getString(R.string.app_name));
        builder.setContentText(getString(R.string.notify_background_connection_enabled));
        builder.setPriority(-2);
        builder.setWhen(0L);
        builder.setContentIntent(activity);
        builder.setSmallIcon(R.drawable.notification_permanent);
        if (Build.VERSION.SDK_INT >= 26) {
            createFgNotificationChannel(this);
            builder.setChannelId(NotificationCenter.CH_PERMANENT);
        }
        return builder.build();
    }

    private static void createFgNotificationChannel(Context context) {
        Object systemService;
        if (ch_created) {
            return;
        }
        ch_created = true;
        NotificationChannel m = ViewUtil$$ExternalSyntheticApiModelOutline0.m(NotificationCenter.CH_PERMANENT, "Receive messages in background.", 1);
        m.setDescription("Ensure reliable message receiving.");
        systemService = context.getSystemService((Class<Object>) NotificationManager.class);
        ((NotificationManager) systemService).createNotificationChannel(m);
    }
}