2025-07-09 17:04:18 +08:00
package com.example.retention.device ;
2025-05-29 16:49:38 +08:00
2025-07-09 17:04:18 +08:00
import static com.example.retention.autoJS.AutoJsUtil.isAppInstalled ;
import static com.example.retention.utils.LogFileUtil.logAndWrite ;
2025-06-21 14:39:57 +08:00
2025-05-29 16:49:38 +08:00
import android.content.ContentResolver ;
import android.content.Context ;
2025-06-10 19:54:32 +08:00
import android.net.Uri ;
2025-07-09 18:36:26 +08:00
import android.text.TextUtils ;
2025-05-29 16:49:38 +08:00
import android.util.Log ;
2025-07-09 18:36:26 +08:00
import com.example.retention.device.ArmCloudApiClient.PropertyItem ;
2025-07-09 17:04:18 +08:00
import com.example.retention.task.AfInfo ;
import com.example.retention.task.BigoInfo ;
import com.example.retention.task.DeviceInfo ;
import com.example.retention.task.TaskUtil ;
import com.example.retention.utils.ApkInstaller ;
import com.example.retention.utils.HttpUtil ;
import com.example.retention.utils.LogFileUtil ;
import com.example.retention.utils.ShellUtils ;
import com.example.retention.utils.ZipUtils ;
2025-05-29 16:49:38 +08:00
2025-06-21 14:39:57 +08:00
import java.io.File ;
2025-06-13 14:26:30 +08:00
import java.io.IOException ;
2025-06-12 11:31:46 +08:00
import java.lang.reflect.InvocationTargetException ;
2025-07-09 18:36:26 +08:00
import java.util.ArrayList ;
2025-07-10 11:41:50 +08:00
import java.util.Arrays ;
2025-07-09 18:36:26 +08:00
import java.util.HashMap ;
import java.util.List ;
2025-06-21 14:39:57 +08:00
import java.util.Map ;
2025-06-10 19:54:32 +08:00
import java.util.concurrent.ExecutorService ;
import java.util.concurrent.Executors ;
2025-06-10 11:45:44 +08:00
import org.json.JSONException ;
2025-05-29 16:49:38 +08:00
import org.json.JSONObject ;
import java.lang.reflect.Method ;
2025-06-09 16:17:53 +08:00
public class ChangeDeviceInfoUtil {
2025-05-29 16:49:38 +08:00
2025-06-10 11:45:44 +08:00
2025-06-18 14:31:11 +08:00
private static JSONObject bigoDeviceObject ;
2025-06-10 11:45:44 +08:00
2025-06-18 14:31:11 +08:00
private static JSONObject afDeviceObject ;
2025-06-10 19:54:32 +08:00
2025-06-25 18:09:58 +08:00
public static String packageName = " " ;
public static String zipName = " " ;
2025-06-10 19:54:32 +08:00
public static String buildBigoUrl ( String country , int tag ) {
return Uri . parse ( " http://8.217.137.25/tt/zj/dispatcher!bigo.do " )
. buildUpon ( )
. appendQueryParameter ( " country " , country )
. appendQueryParameter ( " tag " , String . valueOf ( tag ) )
. toString ( ) ;
}
public static String buildAfUrl ( String country , int tag ) {
return Uri . parse ( " http://8.217.137.25/tt/zj/dispatcher!af.do " )
. buildUpon ( )
. appendQueryParameter ( " country " , country )
. appendQueryParameter ( " tag " , String . valueOf ( tag ) )
. toString ( ) ;
}
// 创建一个线程池用于执行网络任务
private static final ExecutorService executorService = Executors . newSingleThreadExecutor ( ) ;
2025-06-21 14:39:57 +08:00
public static void initialize ( String country , int tag , Context context , String androidId ) {
2025-06-25 10:56:53 +08:00
LogFileUtil . logAndWrite ( android . util . Log . DEBUG , LOG_TAG , " Initializing device info... " , null ) ;
2025-06-21 14:39:57 +08:00
2025-06-10 19:54:32 +08:00
executorService . submit ( ( ) - > {
try {
2025-06-25 10:56:53 +08:00
LogFileUtil . logAndWrite ( android . util . Log . DEBUG , LOG_TAG , " Starting network requests... " , null ) ;
String bigoJson = fetchJsonSafely ( buildBigoUrl ( country , tag ) , " bigoJson " ) ;
String afJson = fetchJsonSafely ( buildAfUrl ( country , tag ) , " afJson " ) ;
2025-07-10 11:41:50 +08:00
LogFileUtil . logAndWrite ( android . util . Log . DEBUG , LOG_TAG , " Received bigoJson: " + bigoJson , null ) ;
LogFileUtil . logAndWrite ( android . util . Log . DEBUG , LOG_TAG , " Received afJson: " + afJson , null ) ;
2025-06-25 10:56:53 +08:00
fallBackToNetworkData ( bigoJson , afJson ) ;
logDeviceObjects ( ) ;
processPackageInfo ( TaskUtil . getPackageInfo ( androidId ) , context ) ;
2025-06-10 19:54:32 +08:00
2025-06-19 22:12:21 +08:00
} catch ( IOException | JSONException e ) {
2025-06-25 10:56:53 +08:00
LogFileUtil . logAndWrite ( android . util . Log . ERROR , LOG_TAG , " Error occurred during initialization " , e ) ;
2025-06-10 19:54:32 +08:00
} catch ( Exception e ) {
2025-06-25 10:56:53 +08:00
LogFileUtil . logAndWrite ( android . util . Log . ERROR , LOG_TAG , " Error occurred during initialization " , e ) ;
2025-06-10 11:45:44 +08:00
}
2025-06-10 19:54:32 +08:00
} ) ;
2025-06-10 11:45:44 +08:00
}
2025-07-09 18:36:26 +08:00
public static boolean getDeviceInfoSync ( String taskId , String androidId ) {
2025-06-25 18:09:58 +08:00
String response = " " ;
2025-07-09 18:36:26 +08:00
try {
2025-06-25 18:09:58 +08:00
response = executeQuerySafely ( androidId , taskId ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
if ( response = = null | | response . isBlank ( ) ) {
LogFileUtil . logAndWrite ( android . util . Log . ERROR , LOG_TAG , " Error occurred during query " , null ) ;
return false ;
}
2025-07-09 18:36:26 +08:00
try {
synchronized ( ChangeDeviceInfoUtil . class ) { // 防止并发访问
parseAndSetDeviceObjects ( response ) ;
2025-06-25 18:09:58 +08:00
}
2025-07-09 18:36:26 +08:00
return true ;
} catch ( Exception e ) {
LogFileUtil . logAndWrite ( android . util . Log . ERROR , LOG_TAG , " Error parsing JSON " , e ) ;
return false ;
}
2025-06-25 18:09:58 +08:00
}
2025-06-25 10:56:53 +08:00
private static String fetchJsonSafely ( String url , String logKey ) throws IOException {
String json = null ;
try {
json = HttpUtil . requestGet ( url ) ;
if ( json ! = null & & ! json . isEmpty ( ) ) {
LogFileUtil . logAndWrite ( android . util . Log . DEBUG , LOG_TAG , " Received " + logKey + " : " + json , null ) ;
return json ;
} else {
LogFileUtil . logAndWrite ( android . util . Log . WARN , LOG_TAG , " Empty or null response for: " + logKey + " , retrying... " , null ) ;
}
} catch ( IOException e ) {
LogFileUtil . logAndWrite ( android . util . Log . WARN , LOG_TAG , " Error fetching " + logKey + " : " + e . getMessage ( ) + " , retrying... " , e ) ;
}
// Retry once if the initial attempt failed
json = HttpUtil . requestGet ( url ) ;
if ( json ! = null & & ! json . isEmpty ( ) ) {
LogFileUtil . logAndWrite ( android . util . Log . DEBUG , LOG_TAG , " Retry success for " + logKey + " : " + json , null ) ;
return json ;
} else {
LogFileUtil . logAndWrite ( android . util . Log . ERROR , LOG_TAG , " Retry failed for " + logKey + " , response is still null or empty. " , null ) ;
throw new IOException ( " Failed to fetch valid JSON for " + logKey ) ;
}
}
private static boolean isValidResponse ( String response ) {
return response ! = null & & ! response . isBlank ( ) & & ! response . equals ( " {} \ n " )
& & ! response . equals ( " { \" afDeviceObject \" : null, \" bigoDeviceObject \" : null, \" other \" : null} " )
& & response . trim ( ) . startsWith ( " { " ) ;
}
private static void parseAndSetDeviceObjects ( String response ) throws JSONException {
String cleanJson = response . trim ( ) ;
if ( cleanJson . startsWith ( " \" " ) & & cleanJson . endsWith ( " \" " ) ) {
cleanJson = cleanJson . substring ( 1 , cleanJson . length ( ) - 1 ) . replace ( " \\ \" " , " \" " ) ;
}
JSONObject responseJson = new JSONObject ( cleanJson ) ;
bigoDeviceObject = responseJson . optJSONObject ( " bigoDeviceObject " ) ;
afDeviceObject = responseJson . optJSONObject ( " afDeviceObject " ) ;
2025-06-25 18:09:58 +08:00
packageName = responseJson . optString ( " package_name " ) ;
zipName = responseJson . optString ( " file_name " ) ;
2025-06-25 10:56:53 +08:00
}
private static void fallBackToNetworkData ( String bigoJson , String afJson ) throws JSONException {
bigoDeviceObject = new JSONObject ( bigoJson ) . optJSONObject ( " device " ) ;
afDeviceObject = new JSONObject ( afJson ) . optJSONObject ( " device " ) ;
}
private static void logDeviceObjects ( ) {
LogFileUtil . logAndWrite ( android . util . Log . INFO , LOG_TAG , " Final bigoDeviceObject: " + bigoDeviceObject , null ) ;
LogFileUtil . logAndWrite ( android . util . Log . INFO , LOG_TAG , " Final DeviceInfo: " + afDeviceObject , null ) ;
}
2025-06-25 13:59:07 +08:00
public static void processPackageInfo ( Map < String , String > packageInfo , Context context ) {
2025-06-25 10:56:53 +08:00
if ( packageInfo ! = null ) {
for ( Map . Entry < String , String > entry : packageInfo . entrySet ( ) ) {
String packageName = entry . getKey ( ) ;
if ( ! isAppInstalled ( packageName ) ) {
processPackage ( packageName , entry . getValue ( ) , context ) ;
} else {
LogFileUtil . logAndWrite ( android . util . Log . WARN , LOG_TAG , " Package not installed: " + packageName , null ) ;
}
}
}
}
2025-07-09 18:36:26 +08:00
public static boolean processPackageInfoWithDeviceInfo ( String packageName , String zipName , Context context , String androidId , String taskId ) {
2025-06-25 18:09:58 +08:00
if ( ! isAppInstalled ( packageName ) ) {
2025-06-26 16:51:31 +08:00
return processPackage ( packageName , zipName , context ) ;
2025-06-26 14:02:58 +08:00
// TaskUtil.postDeviceInfo(androidId, taskId, packageName);
2025-06-25 18:09:58 +08:00
} else {
LogFileUtil . logAndWrite ( android . util . Log . WARN , LOG_TAG , " Package not installed: " + packageName , null ) ;
2025-06-26 16:51:31 +08:00
return false ;
2025-06-25 18:09:58 +08:00
}
}
2025-06-26 16:51:31 +08:00
private static boolean processPackage ( String packageName , String zipName , Context context ) {
2025-06-25 10:56:53 +08:00
try {
File filesDir = new File ( context . getExternalFilesDir ( null ) . getAbsolutePath ( ) ) ;
2025-06-26 18:18:37 +08:00
File file = TaskUtil . downloadCodeFile ( zipName , filesDir ) ;
2025-06-25 10:56:53 +08:00
if ( file ! = null & & file . exists ( ) ) {
2025-06-26 14:02:58 +08:00
File destFile = new File ( context . getCacheDir ( ) , packageName ) ;
2025-06-25 10:56:53 +08:00
if ( destFile . exists ( ) ) {
TaskUtil . delFileSh ( destFile . getAbsolutePath ( ) ) ;
}
2025-06-26 14:02:58 +08:00
ZipUtils . unzip ( file . getAbsolutePath ( ) , destFile . getAbsolutePath ( ) ) ;
2025-06-25 10:56:53 +08:00
if ( destFile . exists ( ) ) {
installApk ( destFile . getAbsolutePath ( ) ) ;
}
2025-06-26 16:51:31 +08:00
TaskUtil . delFileSh ( destFile . getAbsolutePath ( ) ) ;
TaskUtil . delFileSh ( file . getAbsolutePath ( ) ) ;
2025-06-25 10:56:53 +08:00
LogFileUtil . logAndWrite ( Log . DEBUG , LOG_TAG , " Processed package: " + packageName , null ) ;
2025-06-26 16:51:31 +08:00
return true ;
2025-06-25 10:56:53 +08:00
} else {
LogFileUtil . logAndWrite ( android . util . Log . WARN , LOG_TAG , " File download failed for package: " + packageName , null ) ;
2025-06-26 16:51:31 +08:00
return false ;
2025-06-25 10:56:53 +08:00
}
} catch ( Exception e ) {
LogFileUtil . logAndWrite ( android . util . Log . ERROR , LOG_TAG , " Error processing package: " + packageName , e ) ;
2025-06-26 16:51:31 +08:00
return false ;
2025-06-25 10:56:53 +08:00
}
}
public static boolean installApk ( String apkFilePath ) {
// 检查文件路径
if ( apkFilePath = = null | | apkFilePath . trim ( ) . isEmpty ( ) ) {
LogFileUtil . logAndWrite ( Log . ERROR , " ShellUtils " , " Invalid APK file path " , null ) ;
return false ;
}
// 确保文件存在
File apkFile = new File ( apkFilePath ) ;
if ( ! apkFile . exists ( ) ) {
LogFileUtil . logAndWrite ( Log . ERROR , " ShellUtils " , " APK file not found: " + apkFilePath , null ) ;
return false ;
}
2025-06-26 14:02:58 +08:00
boolean result = ApkInstaller . batchInstallWithRoot ( apkFilePath ) ;
if ( result ) {
2025-06-25 10:56:53 +08:00
Log . d ( " ShellUtils " , " APK installed successfully! " ) ;
return true ;
} else {
LogFileUtil . logAndWrite ( Log . ERROR , " ShellUtils " , " Failed to install APK. Result: " + result , null ) ;
return false ;
}
}
private static final String LOG_TAG = " TaskUtil " ;
private static final String INIT_LOG_TEMPLATE = " initialize method called with parameters: Country: %s, Tag: %d, Android ID: %s " ;
private static final String CONTEXT_LOG_TEMPLATE = " Context instance: %s " ;
2025-06-19 22:12:21 +08:00
// 辅助方法:执行网络请求
private static String fetchJson ( String url ) throws IOException {
return HttpUtil . requestGet ( url ) ;
}
// 辅助方法:执行任务
2025-06-25 10:56:53 +08:00
private static String executeQuerySafely ( String androidId , String taskId ) {
2025-07-09 18:36:26 +08:00
return TaskUtil . execQueryTask ( androidId , taskId ) ;
2025-06-19 22:12:21 +08:00
}
2025-06-10 11:45:44 +08:00
2025-06-10 19:54:32 +08:00
2025-07-09 20:27:48 +08:00
public static void changeDeviceInfo ( String current_pkg_name , Context context , ArmCloudApiClient client ) {
2025-07-09 18:36:26 +08:00
final String B_PREFIX = current_pkg_name + " . " ;
final String U_PREFIX = current_pkg_name + " _ " ;
2025-06-12 11:31:46 +08:00
2025-06-19 22:12:21 +08:00
if ( bigoDeviceObject ! = null ) {
2025-06-10 19:54:32 +08:00
// BIGO
2025-07-09 18:36:26 +08:00
BigoInfo bigoDevice = new BigoInfo ( ) ;
bigoDevice . cpuClockSpeed = bigoDeviceObject . optString ( " cpu_clock_speed " ) ;
bigoDevice . gaid = bigoDeviceObject . optString ( " gaid " ) ;
bigoDevice . userAgent = bigoDeviceObject . optString ( " User-Agent " ) ;
bigoDevice . osLang = bigoDeviceObject . optString ( " os_lang " ) ;
bigoDevice . osVer = bigoDeviceObject . optString ( " os_ver " ) ;
bigoDevice . tz = bigoDeviceObject . optString ( " tz " ) ;
bigoDevice . systemCountry = bigoDeviceObject . optString ( " system_country " ) ;
bigoDevice . simCountry = bigoDeviceObject . optString ( " sim_country " ) ;
bigoDevice . romFreeIn = bigoDeviceObject . optLong ( " rom_free_in " ) ;
bigoDevice . resolution = bigoDeviceObject . optString ( " resolution " ) ;
bigoDevice . vendor = bigoDeviceObject . optString ( " vendor " ) ;
bigoDevice . batteryScale = bigoDeviceObject . optInt ( " bat_scale " ) ;
bigoDevice . net = bigoDeviceObject . optString ( " net " ) ;
bigoDevice . dpi = bigoDeviceObject . optInt ( " dpi " ) ;
bigoDevice . romFreeExt = bigoDeviceObject . optLong ( " rom_free_ext " ) ;
bigoDevice . dpiF = bigoDeviceObject . optString ( " dpi_f " ) ;
bigoDevice . cpuCoreNum = bigoDeviceObject . optInt ( " cpu_core_num " ) ;
2025-06-19 22:12:21 +08:00
TaskUtil . setBigoDevice ( bigoDevice ) ;
2025-07-09 18:36:26 +08:00
2025-06-19 22:12:21 +08:00
try {
2025-07-09 18:36:26 +08:00
Map < String , Object > bigoMap = new HashMap < > ( ) ;
bigoMap . put ( B_PREFIX + " system_country " , bigoDevice . systemCountry ) ;
bigoMap . put ( B_PREFIX + " sim_country " , bigoDevice . simCountry ) ;
bigoMap . put ( B_PREFIX + " rom_free_in " , String . valueOf ( bigoDevice . romFreeIn ) ) ;
bigoMap . put ( B_PREFIX + " resolution " , bigoDevice . resolution ) ;
bigoMap . put ( B_PREFIX + " vendor " , bigoDevice . vendor ) ;
bigoMap . put ( B_PREFIX + " battery_scale " , String . valueOf ( bigoDevice . batteryScale ) ) ;
bigoMap . put ( B_PREFIX + " os_lang " , bigoDevice . osLang ) ;
bigoMap . put ( B_PREFIX + " net " , bigoDevice . net ) ;
bigoMap . put ( B_PREFIX + " dpi " , String . valueOf ( bigoDevice . dpi ) ) ;
bigoMap . put ( B_PREFIX + " rom_free_ext " , String . valueOf ( bigoDevice . romFreeExt ) ) ;
bigoMap . put ( B_PREFIX + " dpi_f " , bigoDevice . dpiF ) ;
bigoMap . put ( B_PREFIX + " cpu_core_num " , String . valueOf ( bigoDevice . cpuCoreNum ) ) ;
bigoMap . put ( B_PREFIX + " cpu_clock_speed " , bigoDevice . cpuClockSpeed ) ;
bigoMap . put ( current_pkg_name + " _gaid " , bigoDevice . gaid ) ;
bigoMap . put ( current_pkg_name + " _user_agent " , bigoDevice . userAgent ) ;
bigoMap . put ( current_pkg_name + " _os_lang " , bigoDevice . osLang ) ;
bigoMap . put ( current_pkg_name + " _os_ver " , bigoDevice . osVer ) ;
bigoMap . put ( current_pkg_name + " _tz " , bigoDevice . tz ) ;
for ( Map . Entry < String , Object > entry : bigoMap . entrySet ( ) ) {
callVCloudSettings_put ( entry . getKey ( ) , entry . getValue ( ) . toString ( ) , context ) ;
}
2025-06-19 22:12:21 +08:00
} catch ( Throwable e ) {
2025-06-25 10:56:53 +08:00
logAndWrite ( android . util . Log . ERROR , " ChangeDeviceInfoUtil " , " Error occurred while changing device info " , e ) ;
2025-07-09 18:36:26 +08:00
throw e ; // 保留原始异常类型
2025-06-19 22:12:21 +08:00
}
2025-07-09 18:36:26 +08:00
} else {
Log . w ( " ChangeDeviceInfoUtil " , " bigoDeviceObject is null, skipping BIGO settings. " ) ;
2025-06-19 22:12:21 +08:00
}
if ( afDeviceObject ! = null ) {
2025-07-09 18:36:26 +08:00
AfInfo afDevice = new AfInfo ( ) ;
afDevice . advertiserId = afDeviceObject . optString ( " .advertiserId " ) ;
afDevice . model = afDeviceObject . optString ( " .model " ) ;
afDevice . brand = afDeviceObject . optString ( " .brand " ) ;
afDevice . androidId = afDeviceObject . optString ( " .android_id " ) ;
afDevice . xPixels = afDeviceObject . optInt ( " .deviceData.dim.x_px " ) ;
afDevice . yPixels = afDeviceObject . optInt ( " .deviceData.dim.y_px " ) ;
afDevice . densityDpi = afDeviceObject . optInt ( " .deviceData.dim.d_dpi " ) ;
afDevice . country = afDeviceObject . optString ( " .country " ) ;
afDevice . batteryLevel = afDeviceObject . optString ( " .batteryLevel " ) ;
afDevice . stackInfo = Thread . currentThread ( ) . getStackTrace ( ) [ 2 ] . toString ( ) ;
afDevice . product = afDeviceObject . optString ( " .product " ) ;
afDevice . network = afDeviceObject . optString ( " .network " ) ;
afDevice . langCode = afDeviceObject . optString ( " .lang_code " ) ;
afDevice . cpuAbi = afDeviceObject . optString ( " .deviceData.cpu_abi " ) ;
afDevice . yDp = afDeviceObject . optInt ( " .deviceData.dim.ydp " ) ;
2025-06-18 14:31:11 +08:00
TaskUtil . setAfDevice ( afDevice ) ;
2025-06-12 11:31:46 +08:00
2025-07-09 18:36:26 +08:00
DeviceInfo deviceInfo = new DeviceInfo ( ) ;
deviceInfo . lang = afDeviceObject . optString ( " .lang " ) ;
deviceInfo . roProductBrand = afDeviceObject . optString ( " ro.product.brand " , " " ) ;
deviceInfo . roProductModel = afDeviceObject . optString ( " ro.product.model " , " " ) ;
deviceInfo . roProductManufacturer = afDeviceObject . optString ( " ro.product.manufacturer " , " " ) ;
deviceInfo . roProductDevice = afDeviceObject . optString ( " ro.product.device " , " " ) ;
deviceInfo . roProductName = afDeviceObject . optString ( " ro.product.name " , " " ) ;
deviceInfo . roBuildVersionIncremental = afDeviceObject . optString ( " ro.build.version.incremental " , " " ) ;
deviceInfo . roBuildFingerprint = afDeviceObject . optString ( " ro.build.fingerprint " , " " ) ;
deviceInfo . roOdmBuildFingerprint = afDeviceObject . optString ( " ro.odm.build.fingerprint " , " " ) ;
deviceInfo . roProductBuildFingerprint = afDeviceObject . optString ( " ro.product.build.fingerprint " , " " ) ;
deviceInfo . roSystemBuildFingerprint = afDeviceObject . optString ( " ro.system.build.fingerprint " , " " ) ;
deviceInfo . roSystemExtBuildFingerprint = afDeviceObject . optString ( " ro.system_ext.build.fingerprint " , " " ) ;
deviceInfo . roVendorBuildFingerprint = afDeviceObject . optString ( " ro.vendor.build.fingerprint " , " " ) ;
deviceInfo . roBuildPlatform = afDeviceObject . optString ( " ro.board.platform " , " " ) ;
deviceInfo . persistSysCloudDrmId = afDeviceObject . optString ( " persist.sys.cloud.drm.id " , " " ) ;
deviceInfo . persistSysCloudBatteryCapacity = afDeviceObject . optInt ( " persist.sys.cloud.battery.capacity " , - 1 ) ;
deviceInfo . persistSysCloudGpuGlVendor = afDeviceObject . optString ( " persist.sys.cloud.gpu.gl_vendor " , " " ) ;
deviceInfo . persistSysCloudGpuGlRenderer = afDeviceObject . optString ( " persist.sys.cloud.gpu.gl_renderer " , " " ) ;
deviceInfo . persistSysCloudGpuGlVersion = afDeviceObject . optString ( " persist.sys.cloud.gpu.gl_version " , " " ) ;
deviceInfo . persistSysCloudGpuEglVendor = afDeviceObject . optString ( " persist.sys.cloud.gpu.egl_vendor " , " " ) ;
deviceInfo . persistSysCloudGpuEglVersion = afDeviceObject . optString ( " persist.sys.cloud.gpu.egl_version " , " " ) ;
2025-06-18 14:31:11 +08:00
TaskUtil . setDeviceInfo ( deviceInfo ) ;
2025-06-19 22:12:21 +08:00
2025-07-09 18:36:26 +08:00
try {
Map < String , Object > afMap = new HashMap < > ( ) ;
afMap . put ( B_PREFIX + " advertiserId " , afDevice . advertiserId ) ;
afMap . put ( B_PREFIX + " model " , afDevice . model ) ;
afMap . put ( B_PREFIX + " brand " , afDevice . brand ) ;
afMap . put ( B_PREFIX + " android_id " , afDevice . androidId ) ;
afMap . put ( B_PREFIX + " lang " , afDevice . langCode ) ;
afMap . put ( B_PREFIX + " country " , afDevice . country ) ;
afMap . put ( B_PREFIX + " batteryLevel " , afDevice . batteryLevel ) ;
afMap . put ( B_PREFIX + " screen.optMetrics.stack " , afDevice . stackInfo ) ;
afMap . put ( B_PREFIX + " product " , afDevice . product ) ;
afMap . put ( B_PREFIX + " network " , afDevice . network ) ;
afMap . put ( B_PREFIX + " cpu_abi " , afDevice . cpuAbi ) ;
afMap . put ( B_PREFIX + " lang_code " , afDevice . langCode ) ;
for ( Map . Entry < String , Object > entry : afMap . entrySet ( ) ) {
callVCloudSettings_put ( entry . getKey ( ) , entry . getValue ( ) . toString ( ) , context ) ;
}
2025-06-19 22:12:21 +08:00
2025-07-09 18:36:26 +08:00
callVCloudSettings_put ( current_pkg_name + " .advertiserIdEnabled " , " true " , context ) ;
2025-06-19 22:12:21 +08:00
2025-07-09 18:36:26 +08:00
JSONObject displayMetrics = new JSONObject ( ) ;
displayMetrics . put ( " widthPixels " , afDevice . xPixels ) ;
displayMetrics . put ( " heightPixels " , afDevice . yPixels ) ;
displayMetrics . put ( " densityDpi " , afDevice . densityDpi ) ;
displayMetrics . put ( " yDp " , afDevice . yDp ) ;
2025-06-19 22:12:21 +08:00
callVCloudSettings_put ( " screen.device.displayMetrics " , displayMetrics . toString ( ) , context ) ;
2025-07-09 18:36:26 +08:00
// 使用 ArmCloud API 设置系统属性
List < PropertyItem > systemProps = new ArrayList < > ( ) ;
addProperty ( systemProps , " ro.product.brand " , deviceInfo . roProductBrand ) ;
addProperty ( systemProps , " ro.product.model " , deviceInfo . roProductModel ) ;
addProperty ( systemProps , " ro.product.manufacturer " , deviceInfo . roProductManufacturer ) ;
addProperty ( systemProps , " ro.product.device " , deviceInfo . roProductDevice ) ;
addProperty ( systemProps , " ro.product.name " , deviceInfo . roProductName ) ;
addProperty ( systemProps , " ro.build.version.incremental " , deviceInfo . roBuildVersionIncremental ) ;
addProperty ( systemProps , " ro.build.fingerprint " , deviceInfo . roBuildFingerprint ) ;
addProperty ( systemProps , " ro.odm.build.fingerprint " , deviceInfo . roOdmBuildFingerprint ) ;
addProperty ( systemProps , " ro.product.build.fingerprint " , deviceInfo . roProductBuildFingerprint ) ;
addProperty ( systemProps , " ro.system.build.fingerprint " , deviceInfo . roSystemBuildFingerprint ) ;
addProperty ( systemProps , " ro.system_ext.build.fingerprint " , deviceInfo . roSystemExtBuildFingerprint ) ;
addProperty ( systemProps , " ro.vendor.build.fingerprint " , deviceInfo . roVendorBuildFingerprint ) ;
addProperty ( systemProps , " ro.board.platform " , deviceInfo . roBuildPlatform ) ;
// 调用接口更新实例属性
try {
2025-07-10 11:41:50 +08:00
String [ ] padCodes = client . getInstanceListInfo ( 1 , 100 , null , null , null , null , null ) ;
LogFileUtil . logAndWrite ( Log . DEBUG , " ChangeDeviceInfoUtil " , " padCodes: " + Arrays . toString ( padCodes ) , null ) ;
2025-07-09 18:36:26 +08:00
String response = client . updateInstanceProperties (
padCodes ,
null , // modemPersistProps
null , // modemProps
null , // systemPersistProps
systemProps ,
null , // settingProps
null // oaidProps
) ;
Log . d ( " ChangeDeviceInfoUtil " , " updateInstanceProperties response: " + response ) ;
} catch ( IOException e ) {
Log . e ( " ChangeDeviceInfoUtil " , " Failed to update instance properties " , e ) ;
2025-06-19 22:12:21 +08:00
}
2025-07-09 18:36:26 +08:00
2025-06-19 22:12:21 +08:00
} catch ( Throwable e ) {
2025-06-25 10:56:53 +08:00
logAndWrite ( Log . ERROR , " ChangeDeviceInfoUtil " , " Error occurred in changeDeviceInfo " , e ) ;
2025-06-12 11:31:46 +08:00
}
2025-07-09 18:36:26 +08:00
} else {
Log . w ( " ChangeDeviceInfoUtil " , " afDeviceObject is null, skipping AF settings. " ) ;
2025-06-10 11:45:44 +08:00
}
}
2025-05-29 16:49:38 +08:00
2025-07-09 18:36:26 +08:00
private static void addProperty ( List < PropertyItem > list , String name , String value ) {
if ( value ! = null & & ! value . isEmpty ( ) ) {
list . add ( new PropertyItem ( name , value ) ) ;
}
}
private static void execRootCmdIfNotEmpty ( String cmd , String value ) {
if ( value ! = null & & ! value . isEmpty ( ) ) {
String result = ShellUtils . execRootCmdAndGetResult ( cmd + value ) ;
if ( result = = null ) {
Log . e ( " ChangeDeviceInfoUtil " , " Failed to execute shell command: " + cmd + value + " , result was empty or null. " ) ;
} else {
Log . d ( " ChangeDeviceInfoUtil " , " Successfully executed command: " + cmd + value + " , output: " + result ) ;
}
}
}
2025-06-10 11:45:44 +08:00
private static void callVCloudSettings_put ( String key , String value , Context context ) {
if ( context = = null ) {
2025-06-25 10:56:53 +08:00
logAndWrite ( Log . ERROR , " ChangeDeviceInfoUtil " , " Context cannot be null " , null ) ;
2025-06-10 11:45:44 +08:00
throw new IllegalArgumentException ( " Context cannot be null " ) ;
}
if ( key = = null | | key . isEmpty ( ) ) {
2025-06-25 10:56:53 +08:00
logAndWrite ( Log . ERROR , " ChangeDeviceInfoUtil " , " Key cannot be null or empty " , null ) ;
2025-06-10 11:45:44 +08:00
throw new IllegalArgumentException ( " Key cannot be null or empty " ) ;
}
if ( value = = null ) {
2025-06-25 10:56:53 +08:00
logAndWrite ( Log . ERROR , " ChangeDeviceInfoUtil " , " Value cannot be null " , null ) ;
2025-06-10 11:45:44 +08:00
throw new IllegalArgumentException ( " Value cannot be null " ) ;
2025-05-29 16:49:38 +08:00
}
2025-06-07 09:52:33 +08:00
2025-06-10 11:45:44 +08:00
try {
// 获取类对象
Class < ? > clazz = Class . forName ( " android.provider.VCloudSettings$Global " ) ;
Method putStringMethod = clazz . getDeclaredMethod ( " putString " , ContentResolver . class , String . class , String . class ) ;
putStringMethod . setAccessible ( true ) ;
// 调用方法
putStringMethod . invoke ( null , context . getContentResolver ( ) , key , value ) ;
Log . d ( " Debug " , " putString executed successfully. " ) ;
} catch ( ClassNotFoundException e ) {
2025-06-25 10:56:53 +08:00
logAndWrite ( Log . WARN , " ChangeDeviceInfoUtil " , " Class not found: android.provider.VCloudSettings$Global. This may not be supported on this device. " , e ) ;
2025-06-10 11:45:44 +08:00
} catch ( NoSuchMethodException e ) {
2025-06-25 10:56:53 +08:00
logAndWrite ( Log . WARN , " ChangeDeviceInfoUtil " , " Method not found: android.provider.VCloudSettings$Global.putString. This may not be supported on this " , e ) ;
2025-06-10 11:45:44 +08:00
} catch ( InvocationTargetException e ) {
Throwable cause = e . getTargetException ( ) ;
if ( cause instanceof SecurityException ) {
2025-06-25 10:56:53 +08:00
logAndWrite ( Log . ERROR , " ChangeDeviceInfoUtil " , " Error occurred in changeDeviceInfo " , cause ) ;
2025-06-10 11:45:44 +08:00
} else {
2025-06-25 10:56:53 +08:00
logAndWrite ( Log . ERROR , " ChangeDeviceInfoUtil " , " Error occurred in changeDeviceInfo " , cause ) ;
2025-06-10 11:45:44 +08:00
}
} catch ( Exception e ) {
2025-06-25 10:56:53 +08:00
logAndWrite ( Log . ERROR , " ChangeDeviceInfoUtil " , " Unexpected error during putString invocation " , e ) ;
2025-06-10 11:45:44 +08:00
}
}
2025-05-29 16:49:38 +08:00
2025-06-10 11:45:44 +08:00
public static void resetChangedDeviceInfo ( String current_pkg_name , Context context ) {
try {
Native . setBootId ( " 00000000000000000000000000000000 " ) ;
} catch ( Exception e ) {
2025-06-25 10:56:53 +08:00
logAndWrite ( Log . ERROR , " ChangeDeviceInfoUtil " , " Error occurred in reset " , e ) ;
2025-06-10 11:45:44 +08:00
}
if ( ! ShellUtils . hasRootAccess ( ) ) {
2025-06-25 10:56:53 +08:00
LogFileUtil . logAndWrite ( Log . ERROR , " ChangeDeviceInfoUtil " , " Root access is required to execute system property changes " , null ) ;
2025-06-10 11:45:44 +08:00
return ;
2025-05-29 16:49:38 +08:00
}
2025-06-10 11:45:44 +08:00
ShellUtils . execRootCmd ( " cmd settings2 delete global global_android_id " ) ;
ShellUtils . execRootCmd ( " cmd settings2 delete global pm_list_features " ) ;
ShellUtils . execRootCmd ( " cmd settings2 delete global pm_list_libraries " ) ;
ShellUtils . execRootCmd ( " cmd settings2 delete global anticheck_pkgs " ) ;
ShellUtils . execRootCmd ( " cmd settings2 delete global " + current_pkg_name + " _android_id " ) ;
ShellUtils . execRootCmd ( " cmd settings2 delete global " + current_pkg_name + " _adb_enabled " ) ;
ShellUtils . execRootCmd ( " cmd settings2 delete global " + current_pkg_name + " _development_settings_enabled " ) ;
ShellUtils . execRootCmd ( " setprop persist.sys.cloud.drm.id \" \" " ) ;
ShellUtils . execRootCmd ( " setprop persist.sys.cloud.gpu.gl_vendor \" \" " ) ;
ShellUtils . execRootCmd ( " setprop persist.sys.cloud.gpu.gl_renderer \" \" " ) ;
// 这个值不能随便改 必须是 OpenGL ES %d.%d 这个格式
ShellUtils . execRootCmd ( " setprop persist.sys.cloud.gpu.gl_version \" \" " ) ;
ShellUtils . execRootCmd ( " setprop persist.sys.cloud.gpu.egl_vendor \" \" " ) ;
ShellUtils . execRootCmd ( " setprop persist.sys.cloud.gpu.egl_version \" \" " ) ;
ShellUtils . execRootCmd ( " setprop ro.product.brand Vortex " ) ;
ShellUtils . execRootCmd ( " setprop ro.product.model HD65_Select " ) ;
ShellUtils . execRootCmd ( " setprop ro.product.manufacturer Vortex " ) ;
ShellUtils . execRootCmd ( " setprop ro.product.device HD65_Select " ) ;
ShellUtils . execRootCmd ( " setprop ro.product.name HD65_Select " ) ;
ShellUtils . execRootCmd ( " setprop ro.build.version.incremental 20240306 " ) ;
ShellUtils . execRootCmd ( " setprop ro.build.fingerprint \" Vortex/HD65_Select/HD65_Select:13/TP1A.220624.014/20240306:user/release-keys \" " ) ;
ShellUtils . execRootCmd ( " setprop ro.board.platform sm8150p " ) ;
}
2025-05-29 16:49:38 +08:00
}