正在查看: sushain v0.0.42 应用的 ForegroundService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: sushain v0.0.42 应用的 ForegroundService.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package live.videosdk.rnfgservice;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
public class ForegroundService extends Service {
private static Bundle lastNotificationConfig;
private static ForegroundService mInstance;
public Bundle taskConfig;
private int running = 0;
private Handler handler = new Handler();
private Runnable runnableCode = new Runnable() {
@Override
public void run() {
Intent intent = new Intent(ForegroundService.this.getApplicationContext(), (Class<?>) ForegroundServiceTask.class);
intent.putExtras(ForegroundService.this.taskConfig);
ForegroundService.this.getApplicationContext().startService(intent);
ForegroundService.this.taskConfig.getDouble("delay");
int i = (int) ForegroundService.this.taskConfig.getDouble("loopDelay");
Log.d("SuperLog", "" + i);
ForegroundService.this.handler.postDelayed(this, (long) i);
}
};
private boolean ping() {
return true;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
public static boolean isServiceCreated() {
try {
ForegroundService foregroundService = mInstance;
if (foregroundService != null) {
return foregroundService.ping();
}
return false;
} catch (NullPointerException unused) {
return false;
}
}
public static ForegroundService getInstance() {
if (isServiceCreated()) {
return mInstance;
}
return null;
}
public int isRunning() {
return this.running;
}
@Override
public void onCreate() {
this.running = 0;
mInstance = this;
}
@Override
public void onDestroy() {
this.handler.removeCallbacks(this.runnableCode);
this.running = 0;
mInstance = null;
}
private boolean startService(Bundle bundle) {
try {
startForeground((int) bundle.getDouble("id"), NotificationHelper.getInstance(getApplicationContext()).buildNotification(getApplicationContext(), bundle));
this.running++;
lastNotificationConfig = bundle;
return true;
} catch (Exception e) {
Log.e("ForegroundService", "Failed to start service: " + e.getMessage());
return false;
}
}
@Override
public int onStartCommand(Intent intent, int i, int i2) {
String action = intent.getAction();
if (action != null) {
if (action.equals("live.videosdk.rnfgservice.service_start") && intent.getExtras() != null && intent.getExtras().containsKey("live.videosdk.rnfgservice.notif_config")) {
startService(intent.getExtras().getBundle("live.videosdk.rnfgservice.notif_config"));
}
if (action.equals("live.videosdk.rnfgservice.service_update_notification")) {
if (intent.getExtras() != null && intent.getExtras().containsKey("live.videosdk.rnfgservice.notif_config")) {
Bundle bundle = intent.getExtras().getBundle("live.videosdk.rnfgservice.notif_config");
if (this.running <= 0) {
Log.d("ForegroundService", "Update Notification called without a running service, trying to restart service.");
startService(bundle);
} else {
try {
int i3 = (int) bundle.getDouble("id");
Notification buildNotification = NotificationHelper.getInstance(getApplicationContext()).buildNotification(getApplicationContext(), bundle);
getApplicationContext();
((NotificationManager) getSystemService("notification")).notify(i3, buildNotification);
lastNotificationConfig = bundle;
} catch (Exception e) {
Log.e("ForegroundService", "Failed to update notification: " + e.getMessage());
}
}
}
} else if (action.equals("live.videosdk.rnfgservice.service_run_task")) {
int i4 = this.running;
if (i4 <= 0 && lastNotificationConfig == null) {
Log.e("ForegroundService", "Service is not running to run tasks.");
stopSelf();
return 2;
}
if (i4 <= 0) {
Log.d("ForegroundService", "Run Task called without a running service, trying to restart service.");
if (!startService(lastNotificationConfig)) {
Log.e("ForegroundService", "Service is not running to run tasks.");
return 3;
}
}
if (intent.getExtras() != null && intent.getExtras().containsKey("live.videosdk.rnfgservice.task_config")) {
Bundle bundle2 = intent.getExtras().getBundle("live.videosdk.rnfgservice.task_config");
this.taskConfig = bundle2;
try {
if (bundle2.getBoolean("onLoop")) {
this.handler.post(this.runnableCode);
} else {
runHeadlessTask(this.taskConfig);
}
} catch (Exception e2) {
Log.e("ForegroundService", "Failed to start task: " + e2.getMessage());
}
}
} else {
if (action.equals("live.videosdk.rnfgservice.service_stop")) {
int i5 = this.running;
if (i5 > 0) {
int i6 = i5 - 1;
this.running = i6;
if (i6 == 0) {
stopSelf();
lastNotificationConfig = null;
}
} else {
Log.d("ForegroundService", "Service is not running to stop.");
stopSelf();
lastNotificationConfig = null;
}
return 2;
}
if (action.equals("live.videosdk.rnfgservice.service_all")) {
this.running = 0;
mInstance = null;
lastNotificationConfig = null;
stopSelf();
return 2;
}
}
}
return 3;
}
public void runHeadlessTask(Bundle bundle) {
final Intent intent = new Intent(getApplicationContext(), (Class<?>) ForegroundServiceTask.class);
intent.putExtras(bundle);
int i = (int) bundle.getDouble("delay");
if (i <= 0) {
getApplicationContext().startService(intent);
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (ForegroundService.this.running <= 0) {
return;
}
try {
ForegroundService.this.getApplicationContext().startService(intent);
} catch (Exception e) {
Log.e("ForegroundService", "Failed to start delayed headless task: " + e.getMessage());
}
}
}, i);
}
}
}