Skip to content

Commit

Permalink
fix http service error
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyDynamic committed Dec 15, 2024
1 parent e89269b commit b087384
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class Application : Application() {
application = this
configManager = ConfigManager(this)
db = Room.databaseBuilder(this, AppDatabase::class.java, "maiproberplus").build()
startService(Intent(this, HttpServerService::class.java))
this.initProberContext()
}

Expand Down Expand Up @@ -117,6 +116,18 @@ class Application : Application() {
}
}

fun startHttpServer() {
val intent = Intent(this, HttpServerService::class.java)
startService(intent)
}

fun stopHttpServer() {
val intent = Intent(this, HttpServerService::class.java).apply {
action = HttpServerService.STOP_HTTP_SERVICE_INTENT
}
startService(intent)
}

fun initProberContext() {
proberContext = object : ProberContext {
override fun requireConfig(): ConfigStorage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import android.util.Log;

import java.io.IOException;
import java.util.Objects;

public class HttpServerService extends Service {
public static final String STOP_HTTP_SERVICE_INTENT = "io.github.skkydynamic.service.vpn.DISCONNECT";
private static final String TAG = "HttpServerService";
private HttpServer httpServer;
private HttpRedirectServer httpRedirectServer;
Expand All @@ -34,7 +36,13 @@ public IBinder onBind(Intent intent) {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
Log.d("HttpService", "Http service on start command");
if (Objects.equals(intent.getAction(), STOP_HTTP_SERVICE_INTENT)) {
this.httpServer.stop();
this.httpRedirectServer.stop();
Log.d(TAG, "Stop http service");
return START_NOT_STICKY;
}

try {
this.httpServer.start();
this.httpRedirectServer.start();
Expand All @@ -49,5 +57,6 @@ public void onDestroy() {
super.onDestroy();
this.httpServer.stop();
this.httpRedirectServer.stop();
Log.d(TAG, "Stop http service");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,14 @@ fun SyncCompose() {
} else {
startVpnService(context as Activity)
}
application.startHttpServer()
} else {
stopVpnService(context as Activity)
application.stopHttpServer()
}
}
}
},
enabled = !GlobalViewModel.maimaiHooking || !GlobalViewModel.chuniHooking
) {
if (!globalViewModel.isVpnServiceRunning)
Text("开启劫持")
Expand Down Expand Up @@ -328,10 +331,13 @@ private fun startVpnService(activity: Activity) {
}

private fun stopVpnService(activity: Activity) {
val intent = Intent(activity, LocalVpnService::class.java).apply { action = LocalVpnService.DISCONNECT_INTENT }
val intent = Intent(activity, LocalVpnService::class.java).apply {
action = LocalVpnService.DISCONNECT_INTENT
}
activity.startService(intent)
}

private fun checkResourceComplate(context: Context): Boolean {
return context.filesDir.resolve("maimai_song_list.json").exists() || context.filesDir.resolve("chuni_song_list.json").exists()
return context.filesDir.resolve("maimai_song_list.json").exists()
|| context.filesDir.resolve("chuni_song_list.json").exists()
}

0 comments on commit b087384

Please sign in to comment.