From 1d65b8c5aa8d02f008635b3d4608fdd8eda725ac Mon Sep 17 00:00:00 2001 From: yjj38 Date: Fri, 30 May 2025 11:33:35 +0800 Subject: [PATCH] Fix VPN service crash due to unhandled foreground start Addressed issue where `CustomVpnService` fails to properly start in foreground, leading to a `ForegroundServiceDidNotStartInTimeException`. Added handling for service termination and cleanup to prevent abrupt failure. --- .../com/example/studyapp/MainActivity.java | 71 ++++-- .../studyapp/proxy/CustomVpnService.java | 64 +++++ err.log | 239 ++++++++---------- 3 files changed, 211 insertions(+), 163 deletions(-) diff --git a/app/src/main/java/com/example/studyapp/MainActivity.java b/app/src/main/java/com/example/studyapp/MainActivity.java index 31f8262..5779511 100644 --- a/app/src/main/java/com/example/studyapp/MainActivity.java +++ b/app/src/main/java/com/example/studyapp/MainActivity.java @@ -1,6 +1,7 @@ package com.example.studyapp; import android.app.Activity; +import android.app.ActivityManager; import android.app.AlertDialog; import android.content.ComponentName; import android.content.ServiceConnection; @@ -188,45 +189,63 @@ public class MainActivity extends AppCompatActivity { } } + private boolean isServiceRunning(Context context, Class serviceClass) { + ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); + if (manager != null) { + for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + if (serviceClass.getName().equals(service.service.getClassName())) { + return true; + } + } + } + return false; + } + private void stopProxy(Context context) { if (context == null) { Log.e("stopProxy", "上下文为空,无法停止服务"); return; } - boolean isServiceStopped = true; - try { - Object instance = ReflectionHelper.getInstance("com.example.studyapp.proxy.CustomVpnService", "instance"); - if (instance != null) { - // 尝试获取 onDestroy 方法并调用 - Method onDestroyMethod = instance.getClass().getMethod("onDestroy"); - onDestroyMethod.invoke(instance); - Log.d("stopProxy", "服务已成功停止"); - } else { - isServiceStopped = false; - Log.w("stopProxy", "实例为空,服务可能未启动"); - } - } catch (NoSuchMethodException e) { - isServiceStopped = false; - Log.e("stopProxy", "服务未提供 onDestroy 方法: " + e.getMessage(), e); - } catch (InvocationTargetException | IllegalAccessException e) { - isServiceStopped = false; - Log.e("stopProxy", "无法调用 onDestroy 方法: " + e.getMessage(), e); - } catch (Exception e) { - isServiceStopped = false; - Log.e("stopProxy", "停止服务时发生未知错误: " + e.getMessage(), e); + if (!isServiceRunning(context, CustomVpnService.class)) { + Log.w("stopProxy", "服务未运行,无法停止"); + return; } - // 显示用户提示(主线程) - String message = isServiceStopped ? "VPN 服务已停止" : "停止 VPN 服务失败"; - new Handler(Looper.getMainLooper()).post(() -> - Toast.makeText(context, message, Toast.LENGTH_SHORT).show()); + new Thread(() -> { + boolean isServiceStopped = true; + try { + // 通过反射获取服务实例 + Object instance = ReflectionHelper.getInstance("com.example.studyapp.proxy.CustomVpnService", "instance"); + if (instance != null) { + // 获取并调用 stopService 方法 + Method stopServiceMethod = instance.getClass().getDeclaredMethod("stopService", Intent.class); + stopServiceMethod.invoke(instance, intent); + Log.d("stopProxy", "服务已成功停止"); + } else { + isServiceStopped = false; + Log.w("stopProxy", "实例为空,服务可能未启动"); + } + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + isServiceStopped = false; + Log.e("stopProxy", "无法停止服务: " + e.getMessage(), e); + } catch (Exception e) { + isServiceStopped = false; + Log.e("stopProxy", "停止服务时发生未知错误: " + e.getMessage(), e); + } + + // 在主线程中更新用户提示 + String message = isServiceStopped ? "VPN 服务已停止" : "停止 VPN 服务失败"; + new Handler(Looper.getMainLooper()).post(() -> + Toast.makeText(context, message, Toast.LENGTH_SHORT).show()); + }).start(); } + private Intent intent; private void handleVpnPermissionResult(int resultCode) { if (resultCode == RESULT_OK) { - Intent intent = new Intent(this, CustomVpnService.class); + intent = new Intent(this, CustomVpnService.class); if (intent == null) { Log.e("handleVpnPermissionResult", "Intent is null. Cannot start service."); diff --git a/app/src/main/java/com/example/studyapp/proxy/CustomVpnService.java b/app/src/main/java/com/example/studyapp/proxy/CustomVpnService.java index b106b17..dfa6214 100644 --- a/app/src/main/java/com/example/studyapp/proxy/CustomVpnService.java +++ b/app/src/main/java/com/example/studyapp/proxy/CustomVpnService.java @@ -2,12 +2,19 @@ package com.example.studyapp.proxy; import static com.example.studyapp.utils.V2rayUtil.isV2rayRunning; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; import android.content.Intent; import android.net.VpnService; import android.os.Build; import android.os.ParcelFileDescriptor; import android.util.Log; +import androidx.core.app.NotificationCompat; + +import com.example.studyapp.R; import com.example.studyapp.config.ConfigLoader; import com.example.studyapp.utils.V2rayUtil; @@ -35,6 +42,8 @@ public class CustomVpnService extends VpnService { @Override public int onStartCommand(Intent intent, int flags, int startId) { isVpnActive = true; // 服务启动时激活 + // 开始前台服务 + startForeground(NOTIFICATION_ID, createNotification()); try { // 检查 V2ray 是否已启动,避免重复进程 if (!isV2rayRunning()) { @@ -51,6 +60,9 @@ public class CustomVpnService extends VpnService { return START_STICKY; } + private static final int NOTIFICATION_ID = 1; + + private void startVpn() { try { // 配置虚拟网卡 @@ -150,6 +162,25 @@ public class CustomVpnService extends VpnService { return instance; } + private Notification createNotification() { + NotificationManager notificationManager = + (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel( + "vpn_service", + "VPN Service", + NotificationManager.IMPORTANCE_DEFAULT + ); + notificationManager.createNotificationChannel(channel); + } + return new NotificationCompat.Builder(this, "vpn_service") + .setContentTitle("VPN 服务") + .setContentText("VPN 正在运行...") + .setSmallIcon(R.drawable.ic_launcher_foreground) + .build(); + } + + @Override public void onDestroy() { @@ -183,6 +214,39 @@ public class CustomVpnService extends VpnService { Log.i("CustomVpnService", "VPN 服务已销毁"); } + @Override + public boolean stopService(Intent name) { + isVpnActive = false; // 服务停止时停用 + super.stopService(name); + + // 停止处理数据包的线程 + if (vpnTrafficThread != null && vpnTrafficThread.isAlive()) { + vpnTrafficThread.interrupt(); // 中断线程 + try { + vpnTrafficThread.join(); // 等待线程停止 + } catch (InterruptedException e) { + Log.e("CustomVpnService", "Error while stopping vpnTrafficThread", e); + Thread.currentThread().interrupt(); // 重新设置当前线程的中断状态 + } + vpnTrafficThread = null; // 清空线程引用 + } + + // 关闭 VPN 接口 + if (vpnInterface != null) { + try { + vpnInterface.close(); + } catch (IOException e) { + Log.e("CustomVpnService", "Error closing VPN interface: " + e.getMessage(), e); + } + vpnInterface = null; // 避免资源泄露 + } + + // 停止 V2Ray 服务 + V2rayUtil.stopV2Ray(); + Log.i("CustomVpnService", "VPN 服务已停止"); + return true; + } + private volatile boolean isVpnActive = false; // 标志位控制数据包处理逻辑 diff --git a/err.log b/err.log index ba1f245..8d8caad 100644 --- a/err.log +++ b/err.log @@ -1,137 +1,102 @@ -2025-05-30 10:44:11.434 47349-47349 ShellUtils com.example.studyapp D Executing command: cmd settings2 delete global global_android_id -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: Exception occurred while executing 'delete': -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: java.lang.SecurityException: You either need MANAGE_USERS, CREATE_USERS, or QUERY_USERS permission to: query user -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.checkQueryOrCreateUsersPermission(UserManagerService.java:2854) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.getUserInfo(UserManagerService.java:1428) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getUserInfo(UserController.java:2599) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getCurrentUser(UserController.java:2539) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.ActivityManagerService.getCurrentUser(ActivityManagerService.java:16355) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService$MyShellCommand.onCommand(SettingsService.java:263) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at android.os.ShellCommand.exec(ShellCommand.java:38) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService.onShellCommand(SettingsService.java:55) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.shellCommand(Binder.java:1049) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.onTransact(Binder.java:877) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransactInternal(Binder.java:1285) -2025-05-30 10:44:11.446 47349-48462 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransact(Binder.java:1244) -2025-05-30 10:44:11.450 47349-47349 ShellUtils com.example.studyapp D Executing command: cmd settings2 delete global pm_list_features -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: Exception occurred while executing 'delete': -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: java.lang.SecurityException: You either need MANAGE_USERS, CREATE_USERS, or QUERY_USERS permission to: query user -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.checkQueryOrCreateUsersPermission(UserManagerService.java:2854) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.getUserInfo(UserManagerService.java:1428) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getUserInfo(UserController.java:2599) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getCurrentUser(UserController.java:2539) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.ActivityManagerService.getCurrentUser(ActivityManagerService.java:16355) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService$MyShellCommand.onCommand(SettingsService.java:263) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at android.os.ShellCommand.exec(ShellCommand.java:38) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService.onShellCommand(SettingsService.java:55) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.shellCommand(Binder.java:1049) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.onTransact(Binder.java:877) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransactInternal(Binder.java:1285) -2025-05-30 10:44:11.461 47349-48468 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransact(Binder.java:1244) -2025-05-30 10:44:11.464 47349-47349 ShellUtils com.example.studyapp D Executing command: cmd settings2 delete global pm_list_libraries -2025-05-30 10:44:11.475 47349-48474 ShellUtils com.example.studyapp E Stderr: -2025-05-30 10:44:11.483 47349-48474 ShellUtils com.example.studyapp E Stderr: Exception occurred while executing 'delete': -2025-05-30 10:44:11.483 47349-48474 ShellUtils com.example.studyapp E Stderr: java.lang.SecurityException: You either need MANAGE_USERS, CREATE_USERS, or QUERY_USERS permission to: query user -2025-05-30 10:44:11.483 47349-48474 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.checkQueryOrCreateUsersPermission(UserManagerService.java:2854) -2025-05-30 10:44:11.483 47349-48474 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.getUserInfo(UserManagerService.java:1428) -2025-05-30 10:44:11.483 47349-48474 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getUserInfo(UserController.java:2599) -2025-05-30 10:44:11.483 47349-48474 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getCurrentUser(UserController.java:2539) -2025-05-30 10:44:11.483 47349-48474 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.ActivityManagerService.getCurrentUser(ActivityManagerService.java:16355) -2025-05-30 10:44:11.483 47349-48474 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService$MyShellCommand.onCommand(SettingsService.java:263) -2025-05-30 10:44:11.483 47349-48474 ShellUtils com.example.studyapp E Stderr: at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97) -2025-05-30 10:44:11.483 47349-48474 ShellUtils com.example.studyapp E Stderr: at android.os.ShellCommand.exec(ShellCommand.java:38) -2025-05-30 10:44:11.483 47349-48474 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService.onShellCommand(SettingsService.java:55) -2025-05-30 10:44:11.484 47349-48474 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.shellCommand(Binder.java:1049) -2025-05-30 10:44:11.484 47349-48474 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.onTransact(Binder.java:877) -2025-05-30 10:44:11.484 47349-48474 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransactInternal(Binder.java:1285) -2025-05-30 10:44:11.484 47349-48474 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransact(Binder.java:1244) -2025-05-30 10:44:11.488 47349-47349 ShellUtils com.example.studyapp D Executing command: cmd settings2 delete global anticheck_pkgs -2025-05-30 10:44:11.505 47349-48480 ShellUtils com.example.studyapp E Stderr: -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: Exception occurred while executing 'delete': -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: java.lang.SecurityException: You either need MANAGE_USERS, CREATE_USERS, or QUERY_USERS permission to: query user -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.checkQueryOrCreateUsersPermission(UserManagerService.java:2854) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.getUserInfo(UserManagerService.java:1428) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getUserInfo(UserController.java:2599) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getCurrentUser(UserController.java:2539) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.ActivityManagerService.getCurrentUser(ActivityManagerService.java:16355) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService$MyShellCommand.onCommand(SettingsService.java:263) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at android.os.ShellCommand.exec(ShellCommand.java:38) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService.onShellCommand(SettingsService.java:55) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.shellCommand(Binder.java:1049) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.onTransact(Binder.java:877) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransactInternal(Binder.java:1285) -2025-05-30 10:44:11.506 47349-48480 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransact(Binder.java:1244) -2025-05-30 10:44:11.509 47349-47349 ShellUtils com.example.studyapp D Executing command: cmd settings2 delete global com.example.studyapp_android_id -2025-05-30 10:44:11.520 47349-48486 ShellUtils com.example.studyapp E Stderr: -2025-05-30 10:44:11.520 47349-48486 ShellUtils com.example.studyapp E Stderr: Exception occurred while executing 'delete': -2025-05-30 10:44:11.520 47349-48486 ShellUtils com.example.studyapp E Stderr: java.lang.SecurityException: You either need MANAGE_USERS, CREATE_USERS, or QUERY_USERS permission to: query user -2025-05-30 10:44:11.520 47349-48486 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.checkQueryOrCreateUsersPermission(UserManagerService.java:2854) -2025-05-30 10:44:11.520 47349-48486 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.getUserInfo(UserManagerService.java:1428) -2025-05-30 10:44:11.521 47349-48486 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getUserInfo(UserController.java:2599) -2025-05-30 10:44:11.521 47349-48486 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getCurrentUser(UserController.java:2539) -2025-05-30 10:44:11.521 47349-48486 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.ActivityManagerService.getCurrentUser(ActivityManagerService.java:16355) -2025-05-30 10:44:11.521 47349-48486 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService$MyShellCommand.onCommand(SettingsService.java:263) -2025-05-30 10:44:11.521 47349-48486 ShellUtils com.example.studyapp E Stderr: at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97) -2025-05-30 10:44:11.521 47349-48486 ShellUtils com.example.studyapp E Stderr: at android.os.ShellCommand.exec(ShellCommand.java:38) -2025-05-30 10:44:11.521 47349-48486 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService.onShellCommand(SettingsService.java:55) -2025-05-30 10:44:11.521 47349-48486 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.shellCommand(Binder.java:1049) -2025-05-30 10:44:11.521 47349-48486 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.onTransact(Binder.java:877) -2025-05-30 10:44:11.521 47349-48486 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransactInternal(Binder.java:1285) -2025-05-30 10:44:11.521 47349-48486 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransact(Binder.java:1244) -2025-05-30 10:44:11.527 47349-47349 ShellUtils com.example.studyapp D Executing command: cmd settings2 delete global com.example.studyapp_adb_enabled -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: Exception occurred while executing 'delete': -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: java.lang.SecurityException: You either need MANAGE_USERS, CREATE_USERS, or QUERY_USERS permission to: query user -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.checkQueryOrCreateUsersPermission(UserManagerService.java:2854) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.getUserInfo(UserManagerService.java:1428) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getUserInfo(UserController.java:2599) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getCurrentUser(UserController.java:2539) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.ActivityManagerService.getCurrentUser(ActivityManagerService.java:16355) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService$MyShellCommand.onCommand(SettingsService.java:263) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at android.os.ShellCommand.exec(ShellCommand.java:38) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService.onShellCommand(SettingsService.java:55) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.shellCommand(Binder.java:1049) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.onTransact(Binder.java:877) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransactInternal(Binder.java:1285) -2025-05-30 10:44:11.538 47349-48492 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransact(Binder.java:1244) -2025-05-30 10:44:11.542 47349-47349 ShellUtils com.example.studyapp D Executing command: cmd settings2 delete global com.example.studyapp_development_settings_enabled -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: Exception occurred while executing 'delete': -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: java.lang.SecurityException: You either need MANAGE_USERS, CREATE_USERS, or QUERY_USERS permission to: query user -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.checkQueryOrCreateUsersPermission(UserManagerService.java:2854) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at com.android.server.pm.UserManagerService.getUserInfo(UserManagerService.java:1428) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getUserInfo(UserController.java:2599) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.UserController.getCurrentUser(UserController.java:2539) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at com.android.server.am.ActivityManagerService.getCurrentUser(ActivityManagerService.java:16355) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService$MyShellCommand.onCommand(SettingsService.java:263) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at android.os.ShellCommand.exec(ShellCommand.java:38) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at com.android.providers.settings2.SettingsService.onShellCommand(SettingsService.java:55) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.shellCommand(Binder.java:1049) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.onTransact(Binder.java:877) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransactInternal(Binder.java:1285) -2025-05-30 10:44:11.552 47349-48498 ShellUtils com.example.studyapp E Stderr: at android.os.Binder.execTransact(Binder.java:1244) -2025-05-30 10:44:11.559 47349-47349 ShellUtils com.example.studyapp E Unsafe command, aborting. -2025-05-30 10:44:11.559 47349-47349 ShellUtils com.example.studyapp E Unsafe command, aborting. -2025-05-30 10:44:11.559 47349-47349 ShellUtils com.example.studyapp E Unsafe command, aborting. -2025-05-30 10:44:11.559 47349-47349 ShellUtils com.example.studyapp E Unsafe command, aborting. -2025-05-30 10:44:11.559 47349-47349 ShellUtils com.example.studyapp E Unsafe command, aborting. -2025-05-30 10:44:11.559 47349-47349 ShellUtils com.example.studyapp E Unsafe command, aborting. -2025-05-30 10:44:11.561 47349-47349 ShellUtils com.example.studyapp D Executing command: setprop ro.product.brand Vortex -2025-05-30 10:44:11.577 47349-47349 ShellUtils com.example.studyapp D Executing command: setprop ro.product.model HD65_Select -2025-05-30 10:44:11.596 47349-47349 ShellUtils com.example.studyapp D Executing command: setprop ro.product.manufacturer Vortex -2025-05-30 10:44:11.607 47349-47349 ShellUtils com.example.studyapp D Executing command: setprop ro.product.device HD65_Select -2025-05-30 10:44:11.618 47349-47349 ShellUtils com.example.studyapp D Executing command: setprop ro.product.name HD65_Select -2025-05-30 10:44:11.629 47349-47349 ShellUtils com.example.studyapp D Executing command: setprop ro.build.version.incremental 20240306 -2025-05-30 10:44:11.639 47349-47349 ShellUtils com.example.studyapp E Unsafe command, aborting. -2025-05-30 10:44:11.641 47349-47349 ShellUtils com.example.studyapp D Executing command: setprop ro.board.platform sm8150p -2025-05-30 10:44:18.021 1922-2017 MemInfoService com.android.expansiontools D memScan: [MemEntity(id=null, pid=47349, user=u0_a108, name=Script helper, pkg=com.example.studyapp, res=213, time=2, total=5555, ts=1748573057819, pr=10, ni=-10, virt=14336, shr=122, s=S, cpu=0.0, mem=6.4, args=com.example.studyapp), MemEntity(id=null, pid=44048, user=u0_a100, name=AutoJs6, pkg=org.autojs.autojs6, res=134, time=1, total=5555, ts=1748573057819, pr=20, ni=0, virt=15360, shr=84, s=S, cpu=4.0, mem=4.0, args=org.autojs.autojs6)] -2025-05-30 10:44:19.046 47349-48504 OpenGLRenderer com.example.studyapp I Davey! duration=9184238016ms; Flags=0, FrameTimelineVsyncId=170027, IntendedVsync=62511622785102, Vsync=62511622785102, InputEventId=-800809781, HandleInputStart=62511623260371, AnimationStart=62511627975819, PerformTraversalsStart=62511628155764, DrawStart=62511628386455, FrameDeadline=9246742866199745, FrameInterval=62511623238789, FrameStartTime=16666666, SyncQueued=62511634800612, SyncStart=62511634851650, IssueDrawCommandsStart=62511634937977, SwapBuffers=62511636183011, FrameCompleted=9246749639371862, DequeueBufferDuration=19541, QueueBufferDuration=437760, GpuCompleted=9246749639371862, SwapBuffersCompleted=62511637142525, DisplayPresentTime=-1, CommandSubmissionCompleted=62511636183011, -2025-05-30 10:44:19.286 47349-47377 OpenGLRenderer com.example.studyapp I Davey! duration=9184238008ms; Flags=0, FrameTimelineVsyncId=170126, IntendedVsync=62511865084340, Vsync=62511865084340, InputEventId=-1040841467, HandleInputStart=62511865544853, AnimationStart=62511867959969, PerformTraversalsStart=62511868050379, DrawStart=62511868182202, FrameDeadline=9246749788748896, FrameInterval=62511865534937, FrameStartTime=16666667, SyncQueued=62511871580746, SyncStart=62511871616910, IssueDrawCommandsStart=62511871679030, SwapBuffers=62511872675583, FrameCompleted=9246749873903701, DequeueBufferDuration=14874, QueueBufferDuration=205902, GpuCompleted=9246749873903701, SwapBuffersCompleted=62511873285705, DisplayPresentTime=-1, CommandSubmissionCompleted=62511872675583, -2025-05-30 10:44:28.771 1922-2017 MemInfoService com.android.expansiontools D memScan: [MemEntity(id=null, pid=47349, user=u0_a108, name=Script helper, pkg=com.example.studyapp, res=213, time=3, total=5559, ts=1748573068370, pr=10, ni=-10, virt=14336, shr=122, s=S, cpu=0.0, mem=6.4, args=com.example.studyapp), MemEntity(id=null, pid=44048, user=u0_a100, name=AutoJs6, pkg=org.autojs.autojs6, res=134, time=1, total=5559, ts=1748573068370, pr=20, ni=0, virt=15360, shr=84, s=S, cpu=0.0, mem=4.0, args=org.autojs.autojs6)] +2025-05-30 11:18:50.925 54389-54744 CustomVpnService com.example.studyapp W VPN is not active. Skipping packet processing. +2025-05-30 11:18:50.929 300-315 ActivityManager system_server W Bringing down service while still waiting for start foreground: ServiceRecord{710855b u0 com.example.studyapp/.proxy.CustomVpnService} +---------------------------- PROCESS ENDED (54389) for package com.example.studyapp ---------------------------- +2025-05-30 11:18:50.965 54389-54389 CustomVpnService com.example.studyapp I VPN 服务已停止 +2025-05-30 11:18:50.965 54389-54389 stopProxy com.example.studyapp D 服务已成功停止 +2025-05-30 11:18:50.966 54389-54389 Choreographer com.example.studyapp I Skipped 53 frames! The application may be doing too much work on its main thread. +2025-05-30 11:18:50.970 54389-54389 CustomVpnService com.example.studyapp I VPN 服务已销毁 +2025-05-30 11:18:50.970 54389-54389 AndroidRuntime com.example.studyapp D Shutting down VM +2025-05-30 11:18:50.971 54389-54389 AndroidRuntime com.example.studyapp E FATAL EXCEPTION: main (Ask Gemini) + Process: com.example.studyapp, PID: 54389 + android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{710855b u0 com.example.studyapp/.proxy.CustomVpnService} + at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2005) + at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:1979) + at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0) + at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2241) + at android.os.Handler.dispatchMessage(Handler.java:106) + at android.os.Looper.loopOnce(Looper.java:201) + at android.os.Looper.loop(Looper.java:288) + at android.app.ActivityThread.main(ActivityThread.java:7930) + at java.lang.reflect.Method.invoke(Native Method) + at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) + at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) + Caused by: android.app.StackTrace: Last startServiceCommon() call for this service was made here + at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1915) + at android.app.ContextImpl.startForegroundService(ContextImpl.java:1870) + at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:822) + at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:822) + at com.example.studyapp.MainActivity.handleVpnPermissionResult(MainActivity.java:241) + at com.example.studyapp.MainActivity.onActivityResult(MainActivity.java:175) + at com.example.studyapp.MainActivity.startProxyServer(MainActivity.java:143) + at com.example.studyapp.MainActivity.startProxyVpn(MainActivity.java:127) + at com.example.studyapp.MainActivity.lambda$onCreate$1$com-example-studyapp-MainActivity(MainActivity.java:86) + at com.example.studyapp.MainActivity$$ExternalSyntheticLambda5.onClick(D8$$SyntheticClass:0) + at android.view.View.performClick(View.java:7542) + at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1218) + at android.view.View.performClickInternal(View.java:7519) + at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0) + at android.view.View$PerformClick.run(View.java:29476) + at android.os.Handler.handleCallback(Handler.java:942) + at android.os.Handler.dispatchMessage(Handler.java:99) + at android.os.Looper.loopOnce(Looper.java:201)  + at android.os.Looper.loop(Looper.java:288)  + at android.app.ActivityThread.main(ActivityThread.java:7930)  + at java.lang.reflect.Method.invoke(Native Method)  + at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)  + at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)  +2025-05-30 11:18:50.973 300-4987 ActivityTaskManager system_server W Force finishing activity com.example.studyapp/.MainActivity +2025-05-30 11:18:50.986 54389-54389 Process com.example.studyapp I Sending signal. PID: 54389 SIG: 9 +2025-05-30 11:18:51.022 300-10818 ActivityManager system_server I app.info.packageName:com.example.studyapp app.setKilled(true) +2025-05-30 11:18:51.022 300-10818 ActivityManager system_server I Process com.example.studyapp (pid 54389) has died: fg TOP +2025-05-30 11:18:51.022 300-986 WindowManager system_server I WIN DEATH: Window{ce188c0 u0 com.example.studyapp/com.example.studyapp.MainActivity} +2025-05-30 11:18:51.022 300-986 InputManager-JNI system_server W Input channel object 'ce188c0 com.example.studyapp/com.example.studyapp.MainActivity (client)' was disposed without first being removed with the input manager! +2025-05-30 11:18:51.054 300-319 WindowManager system_server W Failed to deliver inset state change to w=Window{ce188c0 u0 com.example.studyapp/com.example.studyapp.MainActivity EXITING} (Ask Gemini) + android.os.DeadObjectException + at android.os.BinderProxy.transactNative(Native Method) + at android.os.BinderProxy.transact(BinderProxy.java:584) + at android.view.IWindow$Stub$Proxy.insetsControlChanged(IWindow.java:473) + at com.android.server.wm.WindowState.notifyInsetsControlChanged(WindowState.java:4015) + at com.android.server.wm.InsetsStateController.lambda$notifyPendingInsetsControlChanged$4$com-android-server-wm-InsetsStateController(InsetsStateController.java:351) + at com.android.server.wm.InsetsStateController$$ExternalSyntheticLambda2.run(Unknown Source:2) + at com.android.server.wm.WindowAnimator.executeAfterPrepareSurfacesRunnables(WindowAnimator.java:345) + at com.android.server.wm.RootWindowContainer.performSurfacePlacementNoTrace(RootWindowContainer.java:832) + at com.android.server.wm.RootWindowContainer.performSurfacePlacement(RootWindowContainer.java:777) + at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop(WindowSurfacePlacer.java:177) + at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:126) + at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:115) + at com.android.server.wm.WindowSurfacePlacer$Traverser.run(WindowSurfacePlacer.java:57) + at android.os.Handler.handleCallback(Handler.java:942) + at android.os.Handler.dispatchMessage(Handler.java:99) + at android.os.Looper.loopOnce(Looper.java:201) + at android.os.Looper.loop(Looper.java:288) + at android.os.HandlerThread.run(HandlerThread.java:67) + at com.android.server.ServiceThread.run(ServiceThread.java:44) +2025-05-30 11:18:51.054 300-319 WindowManager system_server W Exception thrown during dispatchAppVisibility Window{ce188c0 u0 com.example.studyapp/com.example.studyapp.MainActivity EXITING} (Ask Gemini) + android.os.DeadObjectException + at android.os.BinderProxy.transactNative(Native Method) + at android.os.BinderProxy.transact(BinderProxy.java:584) + at android.view.IWindow$Stub$Proxy.dispatchAppVisibility(IWindow.java:536) + at com.android.server.wm.WindowState.sendAppVisibilityToClients(WindowState.java:3478) + at com.android.server.wm.WindowContainer.sendAppVisibilityToClients(WindowContainer.java:1234) + at com.android.server.wm.WindowToken.setClientVisible(WindowToken.java:392) + at com.android.server.wm.ActivityRecord.setClientVisible(ActivityRecord.java:6865) + at com.android.server.wm.ActivityRecord.onAnimationFinished(ActivityRecord.java:7687) + at com.android.server.wm.ActivityRecord.postApplyAnimation(ActivityRecord.java:5512) + at com.android.server.wm.ActivityRecord.commitVisibility(ActivityRecord.java:5472) + at com.android.server.wm.ActivityRecord.commitVisibility(ActivityRecord.java:5476) + at com.android.server.wm.AppTransitionController.handleClosingApps(AppTransitionController.java:1194) + at com.android.server.wm.AppTransitionController.handleAppTransitionReady(AppTransitionController.java:304) + at com.android.server.wm.RootWindowContainer.checkAppTransitionReady(RootWindowContainer.java:970) + at com.android.server.wm.RootWindowContainer.performSurfacePlacementNoTrace(RootWindowContainer.java:834) + at com.android.server.wm.RootWindowContainer.performSurfacePlacement(RootWindowContainer.java:777) + at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop(WindowSurfacePlacer.java:177) + at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:126) + at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:115) + at com.android.server.wm.WindowSurfacePlacer$Traverser.run(WindowSurfacePlacer.java:57) + at android.os.Handler.handleCallback(Handler.java:942) + at android.os.Handler.dispatchMessage(Handler.java:99) + at android.os.Looper.loopOnce(Looper.java:201) + at android.os.Looper.loop(Looper.java:288) + at android.os.HandlerThread.run(HandlerThread.java:67) + at com.android.server.ServiceThread.run(ServiceThread.java:44) +2025-05-30 11:18:51.473 300-318 ActivityTaskManager system_server W Activity top resumed state loss timeout for ActivityRecord{86432f9 u0 com.example.studyapp/.MainActivity} t-1 f}}