From 23e9b730bfa9c09ae29d69fbe36c4c15bc2815b5 Mon Sep 17 00:00:00 2001 From: yjj38 Date: Mon, 9 Jun 2025 16:45:29 +0800 Subject: [PATCH] Collect detailed device and environment info for VCloud Added system-level data collection for properties like User-Agent, OS version, language, DPI, time zone, network type, ISP, country, and Google Advertising ID (GAID). Integrated `play-services-ads-identifier` dependency for retrieving GAID. Updated `build.gradle` and `libs.versions.toml` accordingly. --- app/build.gradle | 1 + .../studyapp/device/ChangeDeviceInfoUtil.java | 53 +++++++++++++++++++ gradle/libs.versions.toml | 2 + 3 files changed, 56 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 414c880..3317bad 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -59,6 +59,7 @@ dependencies { implementation libs.material implementation libs.activity implementation libs.constraintlayout + implementation libs.play.services.ads.identifier testImplementation libs.junit androidTestImplementation libs.ext.junit androidTestImplementation libs.espresso.core diff --git a/app/src/main/java/com/example/studyapp/device/ChangeDeviceInfoUtil.java b/app/src/main/java/com/example/studyapp/device/ChangeDeviceInfoUtil.java index 91298ee..e57c292 100644 --- a/app/src/main/java/com/example/studyapp/device/ChangeDeviceInfoUtil.java +++ b/app/src/main/java/com/example/studyapp/device/ChangeDeviceInfoUtil.java @@ -6,6 +6,7 @@ import android.util.Log; import com.example.studyapp.utils.ShellUtils; +import com.google.android.gms.ads.identifier.AdvertisingIdClient; import org.json.JSONObject; import java.lang.reflect.InvocationTargetException; @@ -72,6 +73,58 @@ public class ChangeDeviceInfoUtil { callVCloudSettings_put(current_pkg_name + "_screen.getCurrentBounds.stack", ".getDeviceInfo",context); callVCloudSettings_put(current_pkg_name + "_screen.getMaximumBounds.stack", ".getDeviceInfo",context); + // **User-Agent** + String defaultUserAgent = System.getProperty("http.agent"); // 默认 User-Agent + callVCloudSettings_put(current_pkg_name + "_user_agent", defaultUserAgent, context); + + // **os_ver** + String osVer = System.getProperty("os.version"); // 系统版本 + callVCloudSettings_put(current_pkg_name + "_os_ver", osVer, context); + + // **os_lang** + String osLang = context.getResources().getConfiguration().locale.getLanguage(); // 系统语言 + callVCloudSettings_put(current_pkg_name + "_os_lang", osLang, context); + + // **dpi** + JSONObject densityJson = new JSONObject(); + densityJson.put("density", context.getResources().getDisplayMetrics().density); + callVCloudSettings_put(current_pkg_name + "_dpi", densityJson.toString(), context); + + // **dpi_f** + JSONObject realResolutionJson = new JSONObject(); + realResolutionJson.put("width", 411); + realResolutionJson.put("height", 731); + callVCloudSettings_put(current_pkg_name + "_dpi_f", realResolutionJson.toString(), context); + + // **tz** (时区) + String tz = java.util.TimeZone.getDefault().getID(); // 系统时区 + callVCloudSettings_put(current_pkg_name + "_tz", tz, context); + + // **isp** (网络运营商) + android.telephony.TelephonyManager telephonyManager = (android.telephony.TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); + String isp = telephonyManager != null ? telephonyManager.getNetworkOperatorName() : "unknown"; + callVCloudSettings_put(current_pkg_name + "_isp", isp, context); + + // **country** + String country = context.getResources().getConfiguration().locale.getCountry(); + callVCloudSettings_put(current_pkg_name + "_country", country, context); + + // **net** (网络类型:WiFi/流量) + android.net.ConnectivityManager connectivityManager = (android.net.ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + String netType = (connectivityManager != null && + connectivityManager.getActiveNetworkInfo() != null && + connectivityManager.getActiveNetworkInfo().isConnected()) ? + connectivityManager.getActiveNetworkInfo().getTypeName() : "unknown"; + callVCloudSettings_put(current_pkg_name + "_net", netType, context); + + // **gaid** (Google 广告 ID) + try { + AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(context); + String gaid = adInfo != null ? adInfo.getId() : "unknown"; + callVCloudSettings_put(current_pkg_name + "_gaid", gaid, context); + } catch (Throwable e) { + Log.e("ChangeDeviceInfoUtil", "Failed to get GAID", e); + } } catch (Throwable e) { Log.e("ChangeDeviceInfoUtil", "Error occurred while changing device info", e); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d238fa8..82a3b7e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,6 +7,7 @@ appcompat = "1.7.0" material = "1.12.0" activity = "1.10.1" constraintlayout = "2.2.1" +playServicesAdsIdentifier = "18.2.0" [libraries] junit = { group = "junit", name = "junit", version.ref = "junit" } @@ -16,6 +17,7 @@ appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "a material = { group = "com.google.android.material", name = "material", version.ref = "material" } activity = { group = "androidx.activity", name = "activity", version.ref = "activity" } constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" } +play-services-ads-identifier = { group = "com.google.android.gms", name = "play-services-ads-identifier", version.ref = "playServicesAdsIdentifier" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" }