Dynamically fetch and apply device properties from API responses

Implemented dynamic retrieval of device properties from external APIs, parsing JSON responses, and replacing statically hardcoded values. Enhanced flexibility for device information management. Added error handling for JSON parsing and root access validation.
This commit is contained in:
yjj38 2025-06-10 11:45:44 +08:00
parent d2661f8fdb
commit c746633baf
2 changed files with 312 additions and 247 deletions

View File

@ -7,10 +7,12 @@ import android.net.Network;
import android.net.NetworkCapabilities; import android.net.NetworkCapabilities;
import android.util.Log; import android.util.Log;
import com.example.studyapp.utils.HttpUtil;
import com.example.studyapp.utils.ShellUtils; import com.example.studyapp.utils.ShellUtils;
import com.google.android.gms.ads.identifier.AdvertisingIdClient; import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -18,7 +20,80 @@ import java.lang.reflect.Method;
public class ChangeDeviceInfoUtil { public class ChangeDeviceInfoUtil {
private static final String BIGO_URL = "http://8.217.137.25/tt/zj/dispatcher!bigo.do?country=US&tag=2";
private static final JSONObject bigoDeviceObject;
private static final String AF_URL = "http://8.217.137.25/tt/zj/dispatcher!bigo.do?country=US&tag=2";
private static final JSONObject afDeviceObject;
static {
try {
// 请求接口并获取 JSON
String bigoJson = HttpUtil.requestGet(BIGO_URL);
final String afJson = HttpUtil.requestGet(AF_URL);
// 解析 JSON 字符串
JSONObject bigoObject = new JSONObject(bigoJson);
bigoDeviceObject = bigoObject.optJSONObject("device");
JSONObject afObject = new JSONObject(bigoJson);
afDeviceObject = bigoObject.optJSONObject("device");
if (bigoDeviceObject == null) {
throw new JSONException("Device object is missing in the bigo response JSON");
}
if (afDeviceObject == null) {
throw new JSONException("Device object is missing in the af response JSON");
}
Log.d("Debug", "bigoDeviceObject: " + bigoDeviceObject.toString());
Log.d("Debug", "afDeviceObject: " + afDeviceObject.toString());
} catch (Exception e) {
throw new IllegalStateException("Failed to load or parse the response JSON", e);
}
}
public static void changeDeviceInfo(String current_pkg_name, Context context) { public static void changeDeviceInfo(String current_pkg_name, Context context) {
try {
// 动态读取 JSON 中的值
String cpuClockSpeed = bigoDeviceObject.getString("cpu_clock_speed");
// String country = bigoDeviceObject.getString("country");
String gaid = bigoDeviceObject.getString("gaid");
String userAgent = bigoDeviceObject.getString("User-Agent");
String osLang = bigoDeviceObject.getString("os_lang");
String osVer = bigoDeviceObject.getString("os_ver");
// String model = bigoDeviceObject.getString("model");
String tz = bigoDeviceObject.getString("tz");
// 动态读取 JSON 中的值
String advertiserId = afDeviceObject.getString(".advertiserId");
String model = afDeviceObject.getString(".model");
String brand = afDeviceObject.getString(".brand");
String androidId = afDeviceObject.getString(".android_id");
int xPixels = afDeviceObject.optInt(".deviceData.dim.x_px");
int yPixels = afDeviceObject.optInt(".deviceData.dim.y_px");
int densityDpi = afDeviceObject.optInt(".deviceData.dim.d_dpi");
String lang = afDeviceObject.getString(".lang");
String country = afDeviceObject.getString(".country");
String batteryLevel = afDeviceObject.getString(".batteryLevel");
// 替换写死的值为 JSON 动态值
callVCloudSettings_put(current_pkg_name + ".advertiserId", advertiserId, context);
callVCloudSettings_put(current_pkg_name + ".model", model, context);
callVCloudSettings_put(current_pkg_name + ".brand", brand, context);
callVCloudSettings_put(current_pkg_name + ".android_id", androidId, context);
JSONObject displayMetrics = new JSONObject();
displayMetrics.put("widthPixels", xPixels);
displayMetrics.put("heightPixels", yPixels);
displayMetrics.put("densityDpi", densityDpi);
callVCloudSettings_put("screen.getDisplayMetrics", displayMetrics.toString(), context);
callVCloudSettings_put(current_pkg_name + ".lang", lang, context);
callVCloudSettings_put(current_pkg_name + ".country", country, context);
callVCloudSettings_put(current_pkg_name + ".batteryLevel", batteryLevel, context);
Log.d("ChangeDeviceInfoUtil", "Device info successfully updated.");
// 指定包名优先级高于全局 // 指定包名优先级高于全局
callVCloudSettings_put(current_pkg_name + "_android_id", "my123456", context); callVCloudSettings_put(current_pkg_name + "_android_id", "my123456", context);
callVCloudSettings_put(current_pkg_name + "_screen_brightness", "100", context); callVCloudSettings_put(current_pkg_name + "_screen_brightness", "100", context);
@ -34,8 +109,6 @@ public class ChangeDeviceInfoUtil {
callVCloudSettings_put("anticheck_pkgs", current_pkg_name, context); callVCloudSettings_put("anticheck_pkgs", current_pkg_name, context);
try {
JSONObject pkg_info_json = new JSONObject(); JSONObject pkg_info_json = new JSONObject();
pkg_info_json.put("versionName", "1.0.0"); pkg_info_json.put("versionName", "1.0.0");
pkg_info_json.put("versionCode", 100); pkg_info_json.put("versionCode", 100);
@ -59,14 +132,12 @@ public class ChangeDeviceInfoUtil {
callVCloudSettings_put(current_pkg_name + "_screen.getMetrics.stack", stackInfo, context); callVCloudSettings_put(current_pkg_name + "_screen.getMetrics.stack", stackInfo, context);
callVCloudSettings_put(current_pkg_name + "_screen.getRealMetrics.stack", ".getDeviceInfo", context); callVCloudSettings_put(current_pkg_name + "_screen.getRealMetrics.stack", ".getDeviceInfo", context);
tmp_json = new JSONObject(); tmp_json = new JSONObject();
tmp_json.put("width", 1080); tmp_json.put("width", 1080);
tmp_json.put("height", 1820); tmp_json.put("height", 1820);
callVCloudSettings_put("screen.getRealSize", tmp_json.toString(), context); callVCloudSettings_put("screen.getRealSize", tmp_json.toString(), context);
callVCloudSettings_put(current_pkg_name + "_screen.getRealSize.stack", ".getDeviceInfo", context); callVCloudSettings_put(current_pkg_name + "_screen.getRealSize.stack", ".getDeviceInfo", context);
tmp_json = new JSONObject(); tmp_json = new JSONObject();
tmp_json.put("left", 0); tmp_json.put("left", 0);
tmp_json.put("top", 0); tmp_json.put("top", 0);
@ -78,15 +149,12 @@ public class ChangeDeviceInfoUtil {
callVCloudSettings_put(current_pkg_name + "_screen.getMaximumBounds.stack", ".getDeviceInfo", context); callVCloudSettings_put(current_pkg_name + "_screen.getMaximumBounds.stack", ".getDeviceInfo", context);
// **User-Agent** // **User-Agent**
String defaultUserAgent = System.getProperty("http.agent"); // 默认 User-Agent callVCloudSettings_put(current_pkg_name + "_user_agent", userAgent, context);
callVCloudSettings_put(current_pkg_name + "_user_agent", defaultUserAgent, context);
// **os_ver** // **os_ver**
String osVer = System.getProperty("os.version"); // 系统版本
callVCloudSettings_put(current_pkg_name + "_os_ver", osVer, context); callVCloudSettings_put(current_pkg_name + "_os_ver", osVer, context);
// **os_lang** // **os_lang**系统语言
String osLang = context.getResources().getConfiguration().locale.getLanguage(); // 系统语言
callVCloudSettings_put(current_pkg_name + "_os_lang", osLang, context); callVCloudSettings_put(current_pkg_name + "_os_lang", osLang, context);
// **dpi** // **dpi**
@ -101,7 +169,6 @@ public class ChangeDeviceInfoUtil {
callVCloudSettings_put(current_pkg_name + "_dpi_f", realResolutionJson.toString(), context); callVCloudSettings_put(current_pkg_name + "_dpi_f", realResolutionJson.toString(), context);
// **tz** (时区) // **tz** (时区)
String tz = java.util.TimeZone.getDefault().getID(); // 系统时区
callVCloudSettings_put(current_pkg_name + "_tz", tz, context); callVCloudSettings_put(current_pkg_name + "_tz", tz, context);
// **isp** (网络运营商) // **isp** (网络运营商)
@ -148,12 +215,12 @@ public class ChangeDeviceInfoUtil {
callVCloudSettings_put(current_pkg_name + ".app_version_name", "1.0.0", context); callVCloudSettings_put(current_pkg_name + ".app_version_name", "1.0.0", context);
callVCloudSettings_put(current_pkg_name + ".brand", android.os.Build.BRAND, context); callVCloudSettings_put(current_pkg_name + ".brand", android.os.Build.BRAND, context);
callVCloudSettings_put(current_pkg_name + ".device", android.os.Build.DEVICE, context); callVCloudSettings_put(current_pkg_name + ".device", android.os.Build.DEVICE, context);
callVCloudSettings_put(current_pkg_name + ".model", android.os.Build.MODEL, context); callVCloudSettings_put(current_pkg_name + ".model", model, context);
callVCloudSettings_put(current_pkg_name + ".cpu_clock_speed", cpuClockSpeed, context);
// **语言及区域** // **语言及区域**
String lang = context.getResources().getConfiguration().locale.getLanguage(); String lang = context.getResources().getConfiguration().locale.getLanguage();
String langCode = context.getResources().getConfiguration().locale.toString(); String langCode = context.getResources().getConfiguration().locale.toString();
String country = context.getResources().getConfiguration().locale.getCountry();
callVCloudSettings_put(current_pkg_name + ".lang", lang, context); callVCloudSettings_put(current_pkg_name + ".lang", lang, context);
callVCloudSettings_put(current_pkg_name + ".lang_code", langCode, context); callVCloudSettings_put(current_pkg_name + ".lang_code", langCode, context);
callVCloudSettings_put(current_pkg_name + ".country", country, context); callVCloudSettings_put(current_pkg_name + ".country", country, context);
@ -185,11 +252,8 @@ public class ChangeDeviceInfoUtil {
callVCloudSettings_put(current_pkg_name + ".disk", "128GB", context); callVCloudSettings_put(current_pkg_name + ".disk", "128GB", context);
callVCloudSettings_put(current_pkg_name + ".operator", "Fake Operator", context); callVCloudSettings_put(current_pkg_name + ".operator", "Fake Operator", context);
// **gaid** (Google 广告 ID) // **gaid** (Google 广告 ID)
try { try {
AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(context);
String gaid = adInfo != null ? adInfo.getId() : "unknown";
callVCloudSettings_put(current_pkg_name + "_gaid", gaid, context); callVCloudSettings_put(current_pkg_name + "_gaid", gaid, context);
} catch (Throwable e) { } catch (Throwable e) {
Log.e("ChangeDeviceInfoUtil", "Failed to get GAID", e); Log.e("ChangeDeviceInfoUtil", "Failed to get GAID", e);

View File

@ -10,5 +10,6 @@
<domain includeSubdomains="true">47.236.153.142</domain> <domain includeSubdomains="true">47.236.153.142</domain>
<domain includeSubdomains="true">8.211.204.20</domain> <domain includeSubdomains="true">8.211.204.20</domain>
<domain includeSubdomains="true">127.0.0.1</domain> <domain includeSubdomains="true">127.0.0.1</domain>
<domain includeSubdomains="true">8.217.137.25</domain>
</domain-config> </domain-config>
</network-security-config> </network-security-config>