diff --git a/app/src/main/java/com/qwe7002/telegram_rc/chat_command_service.java b/app/src/main/java/com/qwe7002/telegram_rc/chat_command_service.java index 08e2e2c..6513a26 100644 --- a/app/src/main/java/com/qwe7002/telegram_rc/chat_command_service.java +++ b/app/src/main/java/com/qwe7002/telegram_rc/chat_command_service.java @@ -683,7 +683,7 @@ private void receive_handle(@NotNull JsonObject result_obj, boolean get_id_only) request_body.text = getString(R.string.system_message_head) + "\n" + getString(R.string.no_permission); break; } - remote_control_func.force_switch_nic_tether(); + remote_control_func.force_switch_nic_tether(context); request_body.text = getString(R.string.system_message_head) + "\n" + "done."; break; case "/switchtether": diff --git a/app/src/main/java/com/qwe7002/telegram_rc/static_class/remote_control_func.java b/app/src/main/java/com/qwe7002/telegram_rc/static_class/remote_control_func.java index 4bb8856..c07bd9f 100644 --- a/app/src/main/java/com/qwe7002/telegram_rc/static_class/remote_control_func.java +++ b/app/src/main/java/com/qwe7002/telegram_rc/static_class/remote_control_func.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.os.PowerManager; import com.fitc.wifihotspot.TetherManager; @@ -55,12 +56,16 @@ public static void enable_vpn_ap(android.net.wifi.WifiManager wifi_manager) { com.qwe7002.telegram_rc.root_kit.activity_manage.start_foreground_service(const_value.VPN_HOTSPOT_PACKAGE_NAME, const_value.VPN_HOTSPOT_PACKAGE_NAME + ".RepeaterService"); } - public static void force_switch_nic_tether() { + public static void force_switch_nic_tether(Context context) { try { - com.qwe7002.telegram_rc.root_kit.shell.run_shell_command("input keyevent 26"); - Thread.sleep(1000); + PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + //noinspection deprecation + if (!powerManager.isScreenOn()) { + com.qwe7002.telegram_rc.root_kit.shell.run_shell_command("input keyevent 26"); + Thread.sleep(1000); + } com.qwe7002.telegram_rc.root_kit.activity_manage.start_activity("com.android.settings", ".TetherSettings"); - Thread.sleep(1000); + Thread.sleep(3000); com.qwe7002.telegram_rc.root_kit.shell.run_shell_command("input keyevent 20"); Thread.sleep(1000); com.qwe7002.telegram_rc.root_kit.shell.run_shell_command("input keyevent 20"); @@ -73,7 +78,6 @@ public static void force_switch_nic_tether() { Thread.sleep(1000); com.qwe7002.telegram_rc.root_kit.shell.run_shell_command("input keyevent 4"); Thread.sleep(1000); - com.qwe7002.telegram_rc.root_kit.shell.run_shell_command("input keyevent 26"); } catch (InterruptedException e) { e.printStackTrace(); }