feat(proxy): 新增国家代码切换功能并引入OkHttp依赖

- 新增 `CountryCode` 类,用于管理和切换国家代码(目前支持US和RU)。
- 在 `LoadDeviceWorker` 和 `MainActivity` 中引入 `CountryCode` 以实现国家切换。
- `MainActivity` 中的 `startProxyVpn` 方法现在使用 `CountryCode.switchCountry()` 来获取当前国家代码。
- `ClashUtil` 中引入 `okhttp3.logging.HttpLoggingInterceptor`。
- 在 `app/build.gradle` 中添加 `okhttp` 和 `logging-interceptor` 依赖。
- 修改了 `MainActivity` 中 `startProxyVpn` 失败时的日志记录标签。
This commit is contained in:
yjj38 2025-07-09 21:15:17 +08:00
parent d35aa11cdd
commit 84db43d571
5 changed files with 38 additions and 2 deletions

View File

@ -96,11 +96,14 @@ dependencies {
// Mockito
testImplementation 'org.mockito:mockito-core:5.4.0'
// Android Instrumented Tests 使 Mockito
androidTestImplementation 'org.mockito:mockito-android:5.4.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-inline:4.8.0'
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
}

View File

@ -30,6 +30,7 @@ import androidx.work.WorkManager;
import com.example.retention.R;
import com.example.retention.autoJS.AutoJsUtil;
import com.example.retention.config.CountryCode;
import com.example.retention.device.ArmCloudApiClient;
import com.example.retention.device.ChangeDeviceInfoUtil;
@ -211,7 +212,7 @@ public class MainActivity extends AppCompatActivity {
ClashUtil.switchProxyWithPort(CountryCode.switchCountry());
// ClashUtil.switchProxyGroup("PROXY", "my-socks5-proxy", "http://127.0.0.1:6170");
} catch (Exception e) {
LogFileUtil.logAndWrite(Log.ERROR, TAG, "startProxyVpn: Failed to start VPN", e);
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "startProxyVpn: Failed to start VPN", e);
Toast.makeText(context, "Failed to start VPN: " +
(e.getMessage() != null ? e.getMessage() : "Unknown error"),
Toast.LENGTH_SHORT).show();

View File

@ -0,0 +1,30 @@
package com.example.retention.config;
import android.util.Log;
import com.example.retention.utils.LogFileUtil;
/**
* @Time: 2025-08-09 21:08
* @Creator: 初屿贤
* @File: ewfw
* @Project: study.App
* @Description:
*/
public class CountryCode {
public static final int DEVICE_TYPE = 2;
static final String US = "US";
static final String RU = "RU";
// 默认使用美国
static final String DEFAULT = US;
// 当前使用的国家代码
public static String currentCountry = DEFAULT;
public static String switchCountry() {
currentCountry = currentCountry.equals(US) ?
RU : US;
LogFileUtil.logAndWrite(Log.INFO, "TAG",
"Switched country to: " + currentCountry, null);
return currentCountry;
}
}

View File

@ -22,6 +22,7 @@ import okhttp3.RequestBody;
import okhttp3.Response;
import org.json.JSONException;
import org.json.JSONObject;
import okhttp3.logging.HttpLoggingInterceptor;
/**
* @Time: 2025/6/9 11:13

View File

@ -13,6 +13,7 @@ import androidx.work.WorkerParameters;
import com.example.retention.MainActivity;
import com.example.retention.autoJS.AutoJsUtil;
import com.example.retention.config.CountryCode;
import com.example.retention.device.ChangeDeviceInfoUtil;
import com.example.retention.proxy.ClashUtil;
import com.example.retention.utils.LogFileUtil;