diff --git a/app/src/main/java/com/qwe7002/telegram_rc/boot_receiver.java b/app/src/main/java/com/qwe7002/telegram_rc/boot_receiver.java
index 20f2443..8b6c647 100644
--- a/app/src/main/java/com/qwe7002/telegram_rc/boot_receiver.java
+++ b/app/src/main/java/com/qwe7002/telegram_rc/boot_receiver.java
@@ -30,7 +30,7 @@ public void onReceive(@NotNull final Context context, @NotNull Intent intent) {
final SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE);
if (sharedPreferences.getBoolean("initialized", false)) {
log_func.write_log(context, "Received [" + intent.getAction() + "] broadcast, starting background service.");
- service_func.start_service(context, sharedPreferences.getBoolean("battery_monitoring_switch", false), sharedPreferences.getBoolean("chat_command", false), sharedPreferences.getBoolean("wifi_monitor_switch", false));
+ service_func.start_service(context, sharedPreferences.getBoolean("battery_monitoring_switch", false), sharedPreferences.getBoolean("chat_command", false));
if (Paper.book().read("resend_list", new ArrayList<>()).size() != 0) {
Log.d(TAG, "An unsent message was detected, and the automatic resend process was initiated.");
resend_func.start_resend_service(context);
diff --git a/app/src/main/java/com/qwe7002/telegram_rc/main_activity.java b/app/src/main/java/com/qwe7002/telegram_rc/main_activity.java
index f71b624..1165a7f 100644
--- a/app/src/main/java/com/qwe7002/telegram_rc/main_activity.java
+++ b/app/src/main/java/com/qwe7002/telegram_rc/main_activity.java
@@ -129,7 +129,6 @@ protected void onCreate(Bundle savedInstanceState) {
final SwitchMaterial root_switch = findViewById(R.id.root_switch);
final SwitchMaterial privacy_mode_switch = findViewById(R.id.privacy_switch);
final SwitchMaterial display_dual_sim_display_name_switch = findViewById(R.id.display_dual_sim_switch);
- final SwitchMaterial wifi_status_switch = findViewById(R.id.wifi_status_switch);
final Button save_button = findViewById(R.id.save_button);
final Button get_id_button = findViewById(R.id.get_id_button);
usage_button = findViewById(R.id.usage_button);
@@ -137,12 +136,7 @@ protected void onCreate(Bundle savedInstanceState) {
//load config
Paper.init(context);
sharedPreferences = getSharedPreferences("data", MODE_PRIVATE);
- if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
- wifi_status_switch.setChecked(false);
- wifi_status_switch.setVisibility(View.GONE);
- } else {
- wifi_status_switch.setChecked(sharedPreferences.getBoolean("wifi_monitor_switch", false));
- }
+
usage_button.setOnClickListener(v -> {
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
startActivity(intent);
@@ -166,7 +160,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (sharedPreferences.getBoolean("initialized", false)) {
update_config();
check_version_upgrade(true);
- service_func.start_service(context, sharedPreferences.getBoolean("battery_monitoring_switch", false), sharedPreferences.getBoolean("chat_command", false), sharedPreferences.getBoolean("wifi_monitor_switch", false));
+ service_func.start_service(context, sharedPreferences.getBoolean("battery_monitoring_switch", false), sharedPreferences.getBoolean("chat_command", false));
}
@@ -482,11 +476,10 @@ public void onResponse(@NonNull Call call, @NonNull Response response) throws IO
editor.putBoolean("privacy_mode", privacy_mode_switch.isChecked());
editor.putBoolean("initialized", true);
editor.putBoolean("privacy_dialog_agree", true);
- editor.putBoolean("wifi_monitor_switch", wifi_status_switch.isChecked());
editor.apply();
new Thread(() -> {
service_func.stop_all_service(context);
- service_func.start_service(context, battery_monitoring_switch.isChecked(), chat_command_switch.isChecked(), wifi_status_switch.isChecked());
+ service_func.start_service(context, battery_monitoring_switch.isChecked(), chat_command_switch.isChecked());
}).start();
Looper.prepare();
Snackbar.make(v, R.string.success, Snackbar.LENGTH_LONG)
@@ -747,7 +740,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
new Thread(() -> {
service_func.stop_all_service(context);
if (sharedPreferences.getBoolean("initialized", false)) {
- service_func.start_service(context, sharedPreferences.getBoolean("battery_monitoring_switch", false), sharedPreferences.getBoolean("chat_command", false), sharedPreferences.getBoolean("wifi_monitor_switch", false));
+ service_func.start_service(context, sharedPreferences.getBoolean("battery_monitoring_switch", false), sharedPreferences.getBoolean("chat_command", false));
}
}).start();
})
diff --git a/app/src/main/java/com/qwe7002/telegram_rc/sms_receiver.java b/app/src/main/java/com/qwe7002/telegram_rc/sms_receiver.java
index 11799ae..d1e547c 100644
--- a/app/src/main/java/com/qwe7002/telegram_rc/sms_receiver.java
+++ b/app/src/main/java/com/qwe7002/telegram_rc/sms_receiver.java
@@ -145,7 +145,7 @@ public void onReceive(final Context context, @NotNull Intent intent) {
case "/restartservice":
new Thread(() -> {
service_func.stop_all_service(context);
- service_func.start_service(context, sharedPreferences.getBoolean("battery_monitoring_switch", false), sharedPreferences.getBoolean("chat_command", false), sharedPreferences.getBoolean("wifi_monitor_switch", false));
+ service_func.start_service(context, sharedPreferences.getBoolean("battery_monitoring_switch", false), sharedPreferences.getBoolean("chat_command", false));
}).start();
raw_request_body_text = context.getString(R.string.system_message_head) + "\n" + context.getString(R.string.restart_service);
request_body.text = raw_request_body_text;
diff --git a/app/src/main/java/com/qwe7002/telegram_rc/static_class/service_func.java b/app/src/main/java/com/qwe7002/telegram_rc/static_class/service_func.java
index b60b207..cd705e7 100644
--- a/app/src/main/java/com/qwe7002/telegram_rc/static_class/service_func.java
+++ b/app/src/main/java/com/qwe7002/telegram_rc/static_class/service_func.java
@@ -1,6 +1,5 @@
package com.qwe7002.telegram_rc.static_class;
-import android.Manifest;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -11,7 +10,6 @@
import com.qwe7002.telegram_rc.beacon_receiver_service;
import com.qwe7002.telegram_rc.chat_command_service;
import com.qwe7002.telegram_rc.notification_listener_service;
-import com.qwe7002.telegram_rc.wifi_connect_status_service;
import java.util.Set;
@@ -26,10 +24,9 @@ public static void stop_all_service(Context context) {
}
}
- public static void start_service(Context context, Boolean battery_switch, Boolean chat_command_switch, Boolean wifi_status_monitor_switch) {
+ public static void start_service(Context context, Boolean battery_switch, Boolean chat_command_switch) {
Intent battery_service = new Intent(context, com.qwe7002.telegram_rc.battery_service.class);
Intent chat_long_polling_service = new Intent(context, chat_command_service.class);
- Intent wifi_connect_ststus_service = new Intent(context, wifi_connect_status_service.class);
start_beacon_service(context);
if (is_notify_listener(context)) {
ComponentName this_component_name = new ComponentName(context, notification_listener_service.class);
@@ -37,10 +34,6 @@ public static void start_service(Context context, Boolean battery_switch, Boolea
package_manager.setComponentEnabledSetting(this_component_name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
package_manager.setComponentEnabledSetting(this_component_name, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}
- if (wifi_status_monitor_switch && context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
- //Determine whether there is permission
- context.startForegroundService(wifi_connect_ststus_service);
- }
if (battery_switch) {
context.startForegroundService(battery_service);
}
diff --git a/app/src/main/java/com/qwe7002/telegram_rc/ussd_request_callback.java b/app/src/main/java/com/qwe7002/telegram_rc/ussd_request_callback.java
index 0ae8d7a..6ba9423 100644
--- a/app/src/main/java/com/qwe7002/telegram_rc/ussd_request_callback.java
+++ b/app/src/main/java/com/qwe7002/telegram_rc/ussd_request_callback.java
@@ -30,7 +30,6 @@
import okhttp3.RequestBody;
import okhttp3.Response;
-@RequiresApi(api = Build.VERSION_CODES.O)
public class ussd_request_callback extends TelephonyManager.UssdResponseCallback {
private final Context context;
diff --git a/app/src/main/java/com/qwe7002/telegram_rc/wifi_connect_status_service.java b/app/src/main/java/com/qwe7002/telegram_rc/wifi_connect_status_service.java
deleted file mode 100644
index 1023c12..0000000
--- a/app/src/main/java/com/qwe7002/telegram_rc/wifi_connect_status_service.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package com.qwe7002.telegram_rc;
-
-import android.app.Notification;
-import android.app.Service;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.SharedPreferences;
-import android.net.NetworkInfo;
-import android.net.wifi.WifiInfo;
-import android.net.wifi.WifiManager;
-import android.os.IBinder;
-import android.util.Log;
-
-import androidx.annotation.NonNull;
-
-import com.google.gson.Gson;
-import com.qwe7002.telegram_rc.config.proxy;
-import com.qwe7002.telegram_rc.data_structure.request_message;
-import com.qwe7002.telegram_rc.static_class.const_value;
-import com.qwe7002.telegram_rc.static_class.log_func;
-import com.qwe7002.telegram_rc.static_class.network_func;
-import com.qwe7002.telegram_rc.static_class.other_func;
-import com.qwe7002.telegram_rc.static_class.resend_func;
-
-import java.io.IOException;
-import java.util.Objects;
-
-import io.paperdb.Paper;
-import okhttp3.Call;
-import okhttp3.Callback;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.RequestBody;
-import okhttp3.Response;
-
-public class wifi_connect_status_service extends Service {
- private String chat_id;
- private String request_uri;
- private boolean doh_switch;
- private static final String TAG = "wifi_status_change_receiver";
- private Context context;
- private wifi_status_change_receiver wifi_status_change_receiver = null;
- private static NetworkInfo.State last_connect_status = NetworkInfo.State.DISCONNECTED;
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- Notification notification = other_func.get_notification_obj(context, getString(R.string.wifi_status));
- startForeground(com.qwe7002.telegram_rc.notify_id.WIFI_CONNECT_STATUS, notification);
- return START_STICKY;
- }
-
- @Override
- public void onCreate() {
- super.onCreate();
- context = getApplicationContext();
- Paper.init(context);
- wifi_status_change_receiver = new wifi_status_change_receiver();
- IntentFilter filter = new IntentFilter();
- filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
- filter.addAction(const_value.BROADCAST_STOP_SERVICE);
- registerReceiver(wifi_status_change_receiver, filter);
- final SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE);
- if (!sharedPreferences.getBoolean("initialized", false)) {
- Log.i(TAG, "Uninitialized, wifi status receiver is deactivated.");
- return;
- }
- String bot_token = sharedPreferences.getString("bot_token", "");
- chat_id = sharedPreferences.getString("chat_id", "");
- request_uri = network_func.get_url(bot_token, "sendMessage");
- doh_switch = sharedPreferences.getBoolean("doh_switch", true);
-
- }
-
- @Override
- public void onDestroy() {
- unregisterReceiver(wifi_status_change_receiver);
- stopForeground(true);
- super.onDestroy();
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
-
- class wifi_status_change_receiver extends BroadcastReceiver {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(const_value.BROADCAST_STOP_SERVICE)) {
- Log.i(TAG, "Received stop signal, quitting now...");
- stopSelf();
- android.os.Process.killProcess(android.os.Process.myPid());
- return;
- }
- Log.d(TAG, "Receive action: " + intent.getAction());
- NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
- if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
- if (last_connect_status == NetworkInfo.State.CONNECTED) {
- Log.d(TAG, "onReceive: Repeat broadcast");
- return;
- }
- WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
- WifiInfo wifiInfo = wifiManager.getConnectionInfo();
- String message = context.getString(R.string.system_message_head) + "\n" + getString(R.string.connect_to_the_network) + wifiInfo.getSSID();
- request_message request_body = new request_message();
- request_body.chat_id = chat_id;
- request_body.text = message;
- String request_body_json = new Gson().toJson(request_body);
- RequestBody body = RequestBody.create(request_body_json, const_value.JSON);
- OkHttpClient okhttp_client = network_func.get_okhttp_obj(doh_switch, Paper.book("system_config").read("proxy_config", new proxy()));
- Request request = new Request.Builder().url(request_uri).method("POST", body).build();
- Call call = okhttp_client.newCall(request);
- final String error_head = "Send wifi status failed:";
- call.enqueue(new Callback() {
- @Override
- public void onFailure(@NonNull Call call, @NonNull IOException e) {
- e.printStackTrace();
- log_func.write_log(context, error_head + e.getMessage());
- resend_func.add_resend_loop(context, request_body.text);
- }
-
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
- if (response.code() != 200) {
- assert response.body() != null;
- log_func.write_log(context, error_head + response.code() + " " + Objects.requireNonNull(response.body()).string());
- resend_func.add_resend_loop(context, request_body.text);
- }
- }
- });
- }
- last_connect_status = info.getState();
- }
- }
-
-
-}
-
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 9badf1b..8c9764e 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -125,13 +125,6 @@
android:text="@string/root_switch"
tools:ignore="RtlSymmetry" />
-