diff --git a/app/build.gradle b/app/build.gradle index 47c886b..67c7e2f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' + } diff --git a/app/src/main/java/com/example/retention/MainActivity.java b/app/src/main/java/com/example/retention/MainActivity.java index 50d124a..cd5346d 100644 --- a/app/src/main/java/com/example/retention/MainActivity.java +++ b/app/src/main/java/com/example/retention/MainActivity.java @@ -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(); diff --git a/app/src/main/java/com/example/retention/config/CountryCode.java b/app/src/main/java/com/example/retention/config/CountryCode.java new file mode 100644 index 0000000..31d8afe --- /dev/null +++ b/app/src/main/java/com/example/retention/config/CountryCode.java @@ -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; + } +} diff --git a/app/src/main/java/com/example/retention/proxy/ClashUtil.java b/app/src/main/java/com/example/retention/proxy/ClashUtil.java index 099bdd5..690e3ed 100644 --- a/app/src/main/java/com/example/retention/proxy/ClashUtil.java +++ b/app/src/main/java/com/example/retention/proxy/ClashUtil.java @@ -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 diff --git a/app/src/main/java/com/example/retention/worker/LoadDeviceWorker.java b/app/src/main/java/com/example/retention/worker/LoadDeviceWorker.java index 105f807..f239eb0 100644 --- a/app/src/main/java/com/example/retention/worker/LoadDeviceWorker.java +++ b/app/src/main/java/com/example/retention/worker/LoadDeviceWorker.java @@ -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;