正在查看: VIP-LODDER v3.3.1 应用的 LogSenderService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: VIP-LODDER v3.3.1 应用的 LogSenderService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.itsaky.androidide.logsender;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.IBinder;
import android.widget.Toast;
import com.itsaky.androidide.logsender.utils.Logger;
public class LogSenderService extends Service {
public static final String ACTION_START_SERVICE = "ide.logsender.service.start";
public static final String ACTION_STOP_SERVICE = "ide.logsender.service.stop";
private static final String NOTIFICATION_CHANNEL_ID = "ide.logsender.service";
private static final String NOTIFICATION_CHANNEL_NAME = "LogSender Service";
private static final int NOTIFICATION_ID = 644;
private static final String NOTIFICATION_TEXT = "Connected to AndroidIDE";
private static final String NOTIFICATION_TITLE = "LogSender Service";
private final LogSender logSender = new LogSender();
@Override
public void onCreate() {
Logger.LOG.logThis();
super.onCreate();
setupNotificationChannel();
startForeground(NOTIFICATION_ID, buildNotification());
}
@Override
public IBinder onBind(Intent intent) {
Logger.debug("Unexpected request to bind.", intent);
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
char c;
Logger.debug("onStartCommand", intent, Integer.valueOf(flags), Integer.valueOf(startId));
String action = intent.getAction();
switch (action.hashCode()) {
case 1024849076:
if (action.equals(ACTION_STOP_SERVICE)) {
c = 1;
break;
}
c = 65535;
break;
case 1705537008:
if (action.equals(ACTION_START_SERVICE)) {
c = 0;
break;
}
c = 65535;
break;
default:
c = 65535;
break;
}
switch (c) {
case 0:
actionStartService();
return 2;
case 1:
actionStopService();
return 2;
default:
Logger.error("Unknown service action:", intent.getAction());
return 2;
}
}
private void actionStartService() {
Logger.info("Starting log sender service...");
boolean result = false;
try {
result = this.logSender.bind(getApplicationContext());
Logger.debug("Bind to AndroidIDE:", Boolean.valueOf(result));
} catch (Exception err) {
Logger.error(getString(R.string.msg_bind_service_failed), err);
}
if (!result) {
Toast.makeText(this, getString(R.string.msg_bind_service_failed), 0).show();
actionStopService();
}
}
private void actionStopService() {
Logger.info("Stopping log sender service...");
stopSelf();
}
@Override
public void onTaskRemoved(Intent rootIntent) {
Logger.LOG.logThis();
if (!this.logSender.isConnected() && !this.logSender.isBinding()) {
Logger.debug("Not bound to AndroidIDE. Ignored.");
return;
}
Logger.warn("Task removed. Destroying log sender...");
this.logSender.destroy(getApplicationContext());
stopSelf();
}
@Override
public void onDestroy() {
Logger.LOG.logThis();
if (!this.logSender.isConnected() && !this.logSender.isBinding()) {
Logger.debug("Not bound to AndroidIDE. Ignored.");
return;
}
Logger.warn("Service is being destroyed. Destroying log sender...");
this.logSender.destroy(getApplicationContext());
super.onDestroy();
}
private void setupNotificationChannel() {
if (Build.VERSION.SDK_INT < 26) {
return;
}
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "LogSender Service", 2);
NotificationManager notificationManager = (NotificationManager) getSystemService(NotificationManager.class);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
private Notification buildNotification() {
Resources res = getResources();
Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle("LogSender Service");
builder.setContentText(NOTIFICATION_TEXT);
builder.setStyle(new Notification.BigTextStyle().bigText(NOTIFICATION_TEXT));
builder.setPriority(-1);
if (Build.VERSION.SDK_INT >= 26) {
builder.setChannelId(NOTIFICATION_CHANNEL_ID);
}
if (Build.VERSION.SDK_INT >= 17) {
builder.setShowWhen(false);
}
builder.setSmallIcon(R.drawable.ic_androidide_log);
if (Build.VERSION.SDK_INT >= 21) {
builder.setColor(-10453621);
}
builder.setOngoing(true);
Intent exitIntent = new Intent(this, (Class<?>) LogSenderService.class).setAction(ACTION_STOP_SERVICE);
builder.addAction(android.R.drawable.ic_delete, res.getString(R.string.notification_action_exit), PendingIntent.getService(this, 0, exitIntent, 67108864));
return builder.build();
}
}