优化异常处理
This commit is contained in:
parent
87b70e2197
commit
e650ec29c6
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -28,9 +28,11 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||
|
||||
import androidx.work.PeriodicWorkRequest;
|
||||
import androidx.work.WorkManager;
|
||||
|
||||
import com.example.studyapp.autoJS.AutoJsUtil;
|
||||
import com.example.studyapp.device.ChangeDeviceInfoUtil;
|
||||
|
||||
import com.example.studyapp.device.LoadDeviceCallback;
|
||||
import com.example.studyapp.proxy.ClashUtil;
|
||||
import com.example.studyapp.service.MyAccessibilityService;
|
||||
import com.example.studyapp.task.TaskUtil;
|
||||
|
@ -38,6 +40,8 @@ import com.example.studyapp.utils.LogFileUtil;
|
|||
import com.example.studyapp.utils.ShellUtils;
|
||||
import com.example.studyapp.worker.CheckAccessibilityWorker;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -49,53 +53,53 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private static WeakReference<MainActivity> instance;
|
||||
private static WeakReference<MainActivity> instance;
|
||||
|
||||
private static final int REQUEST_CODE_STORAGE_PERMISSION = 1;
|
||||
private static final int REQUEST_CODE_STORAGE_PERMISSION = 1;
|
||||
|
||||
private static final int ALLOW_ALL_FILES_ACCESS_PERMISSION_CODE = 1001;
|
||||
private static final int ALLOW_ALL_FILES_ACCESS_PERMISSION_CODE = 1001;
|
||||
|
||||
public static ExecutorService executorService;
|
||||
public static ExecutorService executorService;
|
||||
|
||||
// 假设我们从配置文件中提取出了以下 name 项数据(仅为部分示例数据)
|
||||
private final String[] proxyNames = {
|
||||
"mr", "sr", "bq", "ml", "ht", "ga", "mk", "by", "pr", "hr", "hu",
|
||||
"in", "gt", "at", "kh", "bn", "mg", "kr", "ca", "gh", "ma", "md",
|
||||
"je", "pa", "ba", "mm", "ir", "gy", "mt", "ae", "es", "ng", "ls",
|
||||
"ag", "pk", "bd", "kn", "mw", "ve", "hk", "cv", "hn", "tm", "us",
|
||||
"cz", "ly", "gb", "kz", "it", "bh", "sn", "fi", "co", "sx", "bm",
|
||||
"fj", "cw", "st", "bw", "fr", "bb", "tg", "ci", "gd", "ne", "bj",
|
||||
"nz", "rs", "do", "cl", "lb", "nl", "re", "aw", "ug", "sv", "ar",
|
||||
"jo", "bg", "jp", "rw", "py", "mn", "ec", "uz", "ro", "cu", "gu",
|
||||
"xk", "sy", "so", "zm", "tz", "ni", "sc", "my", "gf", "na", "zw",
|
||||
"la", "et", "ao", "ua", "om", "np", "mx", "mz", "dm", "ye", "gi",
|
||||
"cr", "cm", "ph", "am", "th", "ch", "br", "sd", "ie", "bo", "bs",
|
||||
"tc", "vg", "pe", "sa", "dk", "tn", "ee", "jm", "lc", "pt", "qa",
|
||||
"ge", "ps"
|
||||
};
|
||||
// 假设我们从配置文件中提取出了以下 name 项数据(仅为部分示例数据)
|
||||
private final String[] proxyNames = {
|
||||
"mr", "sr", "bq", "ml", "ht", "ga", "mk", "by", "pr", "hr", "hu",
|
||||
"in", "gt", "at", "kh", "bn", "mg", "kr", "ca", "gh", "ma", "md",
|
||||
"je", "pa", "ba", "mm", "ir", "gy", "mt", "ae", "es", "ng", "ls",
|
||||
"ag", "pk", "bd", "kn", "mw", "ve", "hk", "cv", "hn", "tm", "us",
|
||||
"cz", "ly", "gb", "kz", "it", "bh", "sn", "fi", "co", "sx", "bm",
|
||||
"fj", "cw", "st", "bw", "fr", "bb", "tg", "ci", "gd", "ne", "bj",
|
||||
"nz", "rs", "do", "cl", "lb", "nl", "re", "aw", "ug", "sv", "ar",
|
||||
"jo", "bg", "jp", "rw", "py", "mn", "ec", "uz", "ro", "cu", "gu",
|
||||
"xk", "sy", "so", "zm", "tz", "ni", "sc", "my", "gf", "na", "zw",
|
||||
"la", "et", "ao", "ua", "om", "np", "mx", "mz", "dm", "ye", "gi",
|
||||
"cr", "cm", "ph", "am", "th", "ch", "br", "sd", "ie", "bo", "bs",
|
||||
"tc", "vg", "pe", "sa", "dk", "tn", "ee", "jm", "lc", "pt", "qa",
|
||||
"ge", "ps"
|
||||
};
|
||||
|
||||
public static volatile String scriptResult;
|
||||
public static volatile String scriptResult;
|
||||
|
||||
// 初始化 ExecutorService
|
||||
private void initializeExecutorService() {
|
||||
if (executorService == null || executorService.isShutdown()) {
|
||||
executorService = new ThreadPoolExecutor(
|
||||
1, // 核心线程数
|
||||
1, // 最大线程数
|
||||
0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<>(50), // 阻塞队列
|
||||
new ThreadPoolExecutor.AbortPolicy() // 拒绝策略
|
||||
);
|
||||
// 初始化 ExecutorService
|
||||
private void initializeExecutorService() {
|
||||
if (executorService == null || executorService.isShutdown()) {
|
||||
executorService = new ThreadPoolExecutor(
|
||||
1, // 核心线程数
|
||||
1, // 最大线程数
|
||||
0L, TimeUnit.MILLISECONDS,
|
||||
new LinkedBlockingQueue<>(50), // 阻塞队列
|
||||
new ThreadPoolExecutor.AbortPolicy() // 拒绝策略
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Android 设备的 ANDROID_ID
|
||||
*
|
||||
* @param context 应用上下文
|
||||
* @return 设备的 ANDROID_ID,若无法获取,则返回 null
|
||||
*/
|
||||
private String getAndroidId(Context context) {
|
||||
/**
|
||||
* 获取 Android 设备的 ANDROID_ID
|
||||
*
|
||||
* @param context 应用上下文
|
||||
* @return 设备的 ANDROID_ID,若无法获取,则返回 null
|
||||
*/
|
||||
private String getAndroidId(Context context) {
|
||||
// if (context == null) {
|
||||
// LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "getAndroidId: Context cannot be null",null);
|
||||
// throw new IllegalArgumentException("Context cannot be null");
|
||||
|
@ -109,320 +113,326 @@ public class MainActivity extends AppCompatActivity {
|
|||
// LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "getAndroidId: Failed to get ANDROID_ID",e);
|
||||
// return null;
|
||||
// }
|
||||
return "FyZqWrStUvOpKlMn";
|
||||
}
|
||||
|
||||
|
||||
private static final int REQUEST_CODE_PERMISSIONS = 100;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
LogFileUtil.initialize(this);
|
||||
setContentView(R.layout.activity_main);
|
||||
instance = new WeakReference<>(this);
|
||||
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "onCreate: Initializing application",null);
|
||||
initializeExecutorService();
|
||||
System.setProperty("java.library.path", this.getApplicationInfo().nativeLibraryDir);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(
|
||||
this,
|
||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||
REQUEST_CODE_STORAGE_PERMISSION
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (!Environment.isExternalStorageManager()) {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
|
||||
intent.setData(Uri.parse("package:" + getPackageName()));
|
||||
startActivityForResult(intent, ALLOW_ALL_FILES_ACCESS_PERMISSION_CODE);
|
||||
}
|
||||
}
|
||||
if (!isNetworkAvailable(this)) {
|
||||
Toast.makeText(this, "Network is not available", Toast.LENGTH_SHORT).show();
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "Network not available, closing app.",null);
|
||||
finish();
|
||||
return "FyZqWrStUvOpKlMn";
|
||||
}
|
||||
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "onCreate: Setting up work manager",null);
|
||||
PeriodicWorkRequest workRequest = new PeriodicWorkRequest.Builder(CheckAccessibilityWorker.class, 15, TimeUnit.MINUTES)
|
||||
.build();
|
||||
WorkManager.getInstance(this).enqueue(workRequest);
|
||||
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "onCreate: Setting up UI components",null);
|
||||
Button runScriptButton = findViewById(R.id.run_script_button);
|
||||
if (runScriptButton != null) {
|
||||
runScriptButton.setOnClickListener(v -> {
|
||||
private static final int REQUEST_CODE_PERMISSIONS = 100;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
LogFileUtil.initialize(this);
|
||||
setContentView(R.layout.activity_main);
|
||||
instance = new WeakReference<>(this);
|
||||
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "onCreate: Initializing application", null);
|
||||
initializeExecutorService();
|
||||
System.setProperty("java.library.path", this.getApplicationInfo().nativeLibraryDir);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(
|
||||
this,
|
||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||
REQUEST_CODE_STORAGE_PERMISSION
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (!Environment.isExternalStorageManager()) {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
|
||||
intent.setData(Uri.parse("package:" + getPackageName()));
|
||||
startActivityForResult(intent, ALLOW_ALL_FILES_ACCESS_PERMISSION_CODE);
|
||||
}
|
||||
}
|
||||
if (!isNetworkAvailable(this)) {
|
||||
Toast.makeText(this, "Network is not available", Toast.LENGTH_SHORT).show();
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "Network not available, closing app.", null);
|
||||
finish();
|
||||
}
|
||||
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "onCreate: Setting up work manager", null);
|
||||
PeriodicWorkRequest workRequest = new PeriodicWorkRequest.Builder(CheckAccessibilityWorker.class, 15, TimeUnit.MINUTES)
|
||||
.build();
|
||||
WorkManager.getInstance(this).enqueue(workRequest);
|
||||
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "onCreate: Setting up UI components", null);
|
||||
Button runScriptButton = findViewById(R.id.run_script_button);
|
||||
if (runScriptButton != null) {
|
||||
runScriptButton.setOnClickListener(v -> {
|
||||
initializeExecutorService();
|
||||
|
||||
executorService.submit(() -> {
|
||||
try {
|
||||
TaskUtil.infoUpload(MainActivity.this, getAndroidId(MainActivity.this), "wsj.reader_sp");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
});
|
||||
// runScriptButton.setOnClickListener(v -> AutoJsUtil.runAutojsScript(this));
|
||||
} else {
|
||||
LogFileUtil.logAndWrite(Log.WARN, "MainActivity", "Run Script Button not found", null);
|
||||
Toast.makeText(this, "Button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
Button connectButton = findViewById(R.id.connectVpnButton);
|
||||
if (connectButton != null) {
|
||||
connectButton.setOnClickListener(v -> startProxyVpn(this));
|
||||
} else {
|
||||
Toast.makeText(this, "Connect button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
Button disconnectButton = findViewById(R.id.disconnectVpnButton);
|
||||
if (disconnectButton != null) {
|
||||
disconnectButton.setOnClickListener(v -> ClashUtil.stopProxy(this));
|
||||
} else {
|
||||
Toast.makeText(this, "Disconnect button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
Button switchVpnButton = findViewById(R.id.switchVpnButton);
|
||||
if (switchVpnButton != null) {
|
||||
switchVpnButton.setOnClickListener(v -> ClashUtil.switchProxyGroup("GLOBAL", "us", "http://127.0.0.1:6170"));
|
||||
} else {
|
||||
Toast.makeText(this, "Disconnect button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
// Button modifyDeviceInfoButton = findViewById(R.id.modifyDeviceInfoButton);
|
||||
// if (modifyDeviceInfoButton != null) {
|
||||
// modifyDeviceInfoButton.setOnClickListener(v -> ChangeDeviceInfoUtil.changeDeviceInfo(getPackageName(), this));
|
||||
// } else {
|
||||
// Toast.makeText(this, "modifyDeviceInfo button not found", Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
|
||||
Button resetDeviceInfoButton = findViewById(R.id.resetDeviceInfoButton);
|
||||
if (resetDeviceInfoButton != null) {
|
||||
resetDeviceInfoButton.setOnClickListener(v -> ChangeDeviceInfoUtil.resetChangedDeviceInfo(getPackageName(), this));
|
||||
} else {
|
||||
Toast.makeText(this, "resetDeviceInfo button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
// 初始化 ChangeDeviceInfoUtil
|
||||
String androidId = getAndroidId(this);
|
||||
String taskId = UUID.randomUUID().toString();
|
||||
// ChangeDeviceInfoUtil.getAddDeviceInfo("US", 2);
|
||||
// 获取输入框和按钮
|
||||
Button executeButton = findViewById(R.id.execute_button);
|
||||
Button stopExecuteButton = findViewById(R.id.stop_execute_button);
|
||||
|
||||
// 设置按钮的点击事件
|
||||
if (executeButton != null) {
|
||||
executeButton.setOnClickListener(v -> {
|
||||
executeButton.setEnabled(false);
|
||||
Toast.makeText(this, "任务正在执行", Toast.LENGTH_SHORT).show();
|
||||
executeLogic(androidId, taskId);
|
||||
});
|
||||
}
|
||||
if (stopExecuteButton != null) {
|
||||
stopExecuteButton.setOnClickListener(v -> {
|
||||
if (executorService != null && !executorService.isShutdown()) {
|
||||
executorService.shutdownNow();
|
||||
ClashUtil.stopProxy(this);
|
||||
AutoJsUtil.stopAutojsScript(this);
|
||||
executeButton.setEnabled(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Toast.makeText(this, "Stop button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void executeLogic(String androidId, String taskId) {
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeLogic: Start execution", null);
|
||||
|
||||
if (!isNetworkAvailable(this)) {
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "executeLogic: Network is not available!", null);
|
||||
Toast.makeText(this, "网络不可用,请检查网络连接", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeLogic: Submitting job to executor", null);
|
||||
initializeExecutorService();
|
||||
|
||||
executorService.submit(() -> {
|
||||
try {
|
||||
TaskUtil.infoUpload(MainActivity.this, getAndroidId(MainActivity.this), "wsj.reader_sp");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
ChangeDeviceInfoUtil.getAddDeviceInfo("US", 2, (bigoDevice, afDevice) -> {
|
||||
startProxyVpn(MainActivity.this);
|
||||
ChangeDeviceInfoUtil.changeDeviceInfo(getPackageName(), MainActivity.this, bigoDevice, afDevice);
|
||||
AutoJsUtil.runAutojsScript(this);
|
||||
});
|
||||
AutoJsUtil.registerScriptResultReceiver(this);
|
||||
AutoJsUtil.flag = true;
|
||||
|
||||
while (isRunning) {
|
||||
if (!isRunning) break;
|
||||
try {
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Running AutoJs script", null);
|
||||
String currentScriptResult = scriptResultQueue.take();
|
||||
ChangeDeviceInfoUtil.getAddDeviceInfo("US", 2, (bigoDevice, afDevice) -> {
|
||||
try {
|
||||
startProxyVpn(MainActivity.this);
|
||||
ChangeDeviceInfoUtil.changeDeviceInfo(getPackageName(), MainActivity.this, bigoDevice, afDevice);
|
||||
AutoJsUtil.runAutojsScript(this);
|
||||
if (currentScriptResult != null && !TextUtils.isEmpty(currentScriptResult)) {
|
||||
TaskUtil.execSaveTask(this, androidId, taskId, currentScriptResult);
|
||||
infoUpload(this, androidId, currentScriptResult);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "changeDeviceInfo erro", e);
|
||||
}
|
||||
});
|
||||
LogFileUtil.logAndWrite(android.util.Log.DEBUG, "MainActivity", "----发送result------;" + currentScriptResult, null);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "loop: Thread interrupted while waiting", e);
|
||||
} catch(Exception e) {
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "loop erro", e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "start executeLogic: Unexpected task error.", e);
|
||||
}
|
||||
});
|
||||
});
|
||||
// runScriptButton.setOnClickListener(v -> AutoJsUtil.runAutojsScript(this));
|
||||
} else {
|
||||
LogFileUtil.logAndWrite(Log.WARN, "MainActivity", "Run Script Button not found",null);
|
||||
Toast.makeText(this, "Button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
Button connectButton = findViewById(R.id.connectVpnButton);
|
||||
if (connectButton != null) {
|
||||
connectButton.setOnClickListener(v -> startProxyVpn(this));
|
||||
} else {
|
||||
Toast.makeText(this, "Connect button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
public static final LinkedBlockingQueue<String> scriptResultQueue = new LinkedBlockingQueue<>();
|
||||
private volatile boolean isRunning = true; // 主线程运行状态
|
||||
public static final Object taskLock = new Object(); // 任务逻辑锁
|
||||
|
||||
Button disconnectButton = findViewById(R.id.disconnectVpnButton);
|
||||
if (disconnectButton != null) {
|
||||
disconnectButton.setOnClickListener(v -> ClashUtil.stopProxy(this));
|
||||
} else {
|
||||
Toast.makeText(this, "Disconnect button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
// public void executeSingleLogic() {
|
||||
//// LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Proxy not active, starting VPN",null);
|
||||
// startProxyVpn(this);
|
||||
// LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Changing device info",null);
|
||||
// ChangeDeviceInfoUtil.changeDeviceInfo(getPackageName(), this);
|
||||
|
||||
Button switchVpnButton = findViewById(R.id.switchVpnButton);
|
||||
if (switchVpnButton != null) {
|
||||
switchVpnButton.setOnClickListener(v -> ClashUtil.switchProxyGroup("GLOBAL", "us", "http://127.0.0.1:6170"));
|
||||
} else {
|
||||
Toast.makeText(this, "Disconnect button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
Button modifyDeviceInfoButton = findViewById(R.id.modifyDeviceInfoButton);
|
||||
if (modifyDeviceInfoButton != null) {
|
||||
modifyDeviceInfoButton.setOnClickListener(v -> ChangeDeviceInfoUtil.changeDeviceInfo(getPackageName(), this));
|
||||
} else {
|
||||
Toast.makeText(this, "modifyDeviceInfo button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
Button resetDeviceInfoButton = findViewById(R.id.resetDeviceInfoButton);
|
||||
if (resetDeviceInfoButton != null) {
|
||||
resetDeviceInfoButton.setOnClickListener(v -> ChangeDeviceInfoUtil.resetChangedDeviceInfo(getPackageName(), this));
|
||||
} else {
|
||||
Toast.makeText(this, "resetDeviceInfo button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
// 初始化 ChangeDeviceInfoUtil
|
||||
String androidId = getAndroidId(this);
|
||||
String taskId = UUID.randomUUID().toString();
|
||||
// ChangeDeviceInfoUtil.getAddDeviceInfo("US", 2);
|
||||
// 获取输入框和按钮
|
||||
Button executeButton = findViewById(R.id.execute_button);
|
||||
Button stopExecuteButton = findViewById(R.id.stop_execute_button);
|
||||
|
||||
// 设置按钮的点击事件
|
||||
if (executeButton != null) {
|
||||
executeButton.setOnClickListener(v -> {
|
||||
executeButton.setEnabled(false);
|
||||
Toast.makeText(this, "任务正在执行", Toast.LENGTH_SHORT).show();
|
||||
executeLogic(androidId,taskId);
|
||||
});
|
||||
}
|
||||
if (stopExecuteButton != null) {
|
||||
stopExecuteButton.setOnClickListener(v -> {
|
||||
if (executorService != null && !executorService.isShutdown()) {
|
||||
executorService.shutdownNow();
|
||||
ClashUtil.stopProxy(this);
|
||||
AutoJsUtil.stopAutojsScript(this);
|
||||
executeButton.setEnabled(true);
|
||||
/// / LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Running AutoJs script",null);
|
||||
// AutoJsUtil.runAutojsScript(this);
|
||||
// }
|
||||
private void startProxyVpn(Context context) {
|
||||
if (!isNetworkAvailable(context)) {
|
||||
Toast.makeText(context, "Network is not available", Toast.LENGTH_SHORT).show();
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "startProxyVpn: Network is not available.", null);
|
||||
return;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Toast.makeText(this, "Stop button not found", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void executeLogic(String androidId, String taskId) {
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeLogic: Start execution",null);
|
||||
|
||||
if (!isNetworkAvailable(this)) {
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "executeLogic: Network is not available!",null);
|
||||
Toast.makeText(this, "网络不可用,请检查网络连接", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeLogic: Submitting job to executor",null);
|
||||
initializeExecutorService();
|
||||
|
||||
executorService.submit(() -> {
|
||||
try {
|
||||
ChangeDeviceInfoUtil.getAddDeviceInfo("US", 2);
|
||||
executeSingleLogic();
|
||||
AutoJsUtil.registerScriptResultReceiver(this);
|
||||
AutoJsUtil.flag = true;
|
||||
|
||||
while (isRunning) {
|
||||
if (!isRunning) break;
|
||||
|
||||
// 从队列中获取最新的 scriptResult
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Running AutoJs script",null);
|
||||
String currentScriptResult = scriptResultQueue.take();
|
||||
ChangeDeviceInfoUtil.getAddDeviceInfo("US", 2);
|
||||
executeSingleLogic();
|
||||
LogFileUtil.logAndWrite(android.util.Log.DEBUG, "MainActivity", "----发送result------;" + currentScriptResult, null);
|
||||
if (currentScriptResult != null && !TextUtils.isEmpty(currentScriptResult)) {
|
||||
TaskUtil.execSaveTask(this, androidId, taskId, currentScriptResult);
|
||||
try {
|
||||
infoUpload(this, androidId, currentScriptResult);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Thread.sleep(5000);
|
||||
if (!(context instanceof Activity)) {
|
||||
Toast.makeText(context, "Context must be an Activity", Toast.LENGTH_SHORT).show();
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "startProxyVpn: Context is not an Activity.", null);
|
||||
return;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "executeLogic: Thread interrupted while waiting", e);
|
||||
} catch (Exception e) {
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "executeLogic: Unexpected task error.", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static final LinkedBlockingQueue<String> scriptResultQueue = new LinkedBlockingQueue<>();
|
||||
private volatile boolean isRunning = true; // 主线程运行状态
|
||||
public static final Object taskLock = new Object(); // 任务逻辑锁
|
||||
|
||||
public void executeSingleLogic() {
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Proxy not active, starting VPN",null);
|
||||
startProxyVpn(this);
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Changing device info",null);
|
||||
ChangeDeviceInfoUtil.changeDeviceInfo(getPackageName(), this);
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Running AutoJs script",null);
|
||||
AutoJsUtil.runAutojsScript(this);
|
||||
}
|
||||
|
||||
|
||||
private void startProxyVpn(Context context) {
|
||||
if (!isNetworkAvailable(context)) {
|
||||
Toast.makeText(context, "Network is not available", Toast.LENGTH_SHORT).show();
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "startProxyVpn: Network is not available.",null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(context instanceof Activity)) {
|
||||
Toast.makeText(context, "Context must be an Activity", Toast.LENGTH_SHORT).show();
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "startProxyVpn: Context is not an Activity.",null);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
ClashUtil.startProxy(context); // 在主线程中调用
|
||||
ClashUtil.switchProxyGroup("GLOBAL", "us", "http://127.0.0.1:6170");
|
||||
} catch (Exception 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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (requestCode == REQUEST_CODE_STORAGE_PERMISSION) {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(this, "Storage Permissions granted", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
// 提示权限被拒绝,同时允许用户重新授予权限
|
||||
showPermissionExplanationDialog();
|
||||
}
|
||||
}
|
||||
if (requestCode == REQUEST_CODE_PERMISSIONS) {
|
||||
boolean allGranted = true;
|
||||
for (int result : grantResults) {
|
||||
if (result != PackageManager.PERMISSION_GRANTED) {
|
||||
allGranted = false;
|
||||
break;
|
||||
try {
|
||||
ClashUtil.startProxy(context); // 在主线程中调用
|
||||
ClashUtil.switchProxyGroup("GLOBAL", "us", "http://127.0.0.1:6170");
|
||||
} catch (Exception 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();
|
||||
}
|
||||
}
|
||||
|
||||
if (allGranted) {
|
||||
// 所有权限已授予
|
||||
startMyForegroundService();
|
||||
} else {
|
||||
Toast.makeText(this, "未授予必要权限,请检查设置", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startMyForegroundService() {
|
||||
Intent serviceIntent = new Intent(this, MyAccessibilityService.class);
|
||||
ContextCompat.startForegroundService(this, serviceIntent);
|
||||
}
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (requestCode == REQUEST_CODE_STORAGE_PERMISSION) {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(this, "Storage Permissions granted", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
// 提示权限被拒绝,同时允许用户重新授予权限
|
||||
showPermissionExplanationDialog();
|
||||
}
|
||||
}
|
||||
if (requestCode == REQUEST_CODE_PERMISSIONS) {
|
||||
boolean allGranted = true;
|
||||
for (int result : grantResults) {
|
||||
if (result != PackageManager.PERMISSION_GRANTED) {
|
||||
allGranted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
switch (requestCode) {
|
||||
case ALLOW_ALL_FILES_ACCESS_PERMISSION_CODE:
|
||||
handleStoragePermissionResult(resultCode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (allGranted) {
|
||||
// 所有权限已授予
|
||||
startMyForegroundService();
|
||||
} else {
|
||||
Toast.makeText(this, "未授予必要权限,请检查设置", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleStoragePermissionResult(int resultCode) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && Environment.isExternalStorageManager()) {
|
||||
Toast.makeText(this, "Storage Permissions granted", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(this, "请授予所有文件管理权限", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
private void startMyForegroundService() {
|
||||
Intent serviceIntent = new Intent(this, MyAccessibilityService.class);
|
||||
ContextCompat.startForegroundService(this, serviceIntent);
|
||||
}
|
||||
}
|
||||
|
||||
private void showPermissionExplanationDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Permission Required")
|
||||
.setMessage("Storage Permission is required for the app to function. Please enable it in Settings.")
|
||||
.setPositiveButton("Go to Settings", (dialog, which) -> {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
startActivity(intent);
|
||||
})
|
||||
.setNegativeButton("Cancel", (dialog, which) -> finish())
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "onDestroy: Cleaning up resources",null);
|
||||
super.onDestroy();
|
||||
instance.clear();
|
||||
if (AutoJsUtil.scriptResultReceiver != null) {
|
||||
unregisterReceiver(AutoJsUtil.scriptResultReceiver);
|
||||
AutoJsUtil.scriptResultReceiver = null;
|
||||
}
|
||||
if (executorService != null) {
|
||||
executorService.shutdown();
|
||||
}
|
||||
isRunning = false;
|
||||
synchronized (taskLock) {
|
||||
taskLock.notifyAll();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
public static MainActivity getInstance() {
|
||||
return instance.get(); // 返回实例
|
||||
}
|
||||
|
||||
private boolean isNetworkAvailable(Context context) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (connectivityManager != null) {
|
||||
Network network = connectivityManager.getActiveNetwork();
|
||||
if (network != null) {
|
||||
NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
|
||||
return capabilities != null && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||
&& capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
|
||||
}
|
||||
switch (requestCode) {
|
||||
case ALLOW_ALL_FILES_ACCESS_PERMISSION_CODE:
|
||||
handleStoragePermissionResult(resultCode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleStoragePermissionResult(int resultCode) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && Environment.isExternalStorageManager()) {
|
||||
Toast.makeText(this, "Storage Permissions granted", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(this, "请授予所有文件管理权限", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void showPermissionExplanationDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Permission Required")
|
||||
.setMessage("Storage Permission is required for the app to function. Please enable it in Settings.")
|
||||
.setPositiveButton("Go to Settings", (dialog, which) -> {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
startActivity(intent);
|
||||
})
|
||||
.setNegativeButton("Cancel", (dialog, which) -> finish())
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "onDestroy: Cleaning up resources", null);
|
||||
super.onDestroy();
|
||||
instance.clear();
|
||||
if (AutoJsUtil.scriptResultReceiver != null) {
|
||||
unregisterReceiver(AutoJsUtil.scriptResultReceiver);
|
||||
AutoJsUtil.scriptResultReceiver = null;
|
||||
}
|
||||
if (executorService != null) {
|
||||
executorService.shutdown();
|
||||
}
|
||||
isRunning = false;
|
||||
synchronized (taskLock) {
|
||||
taskLock.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public static MainActivity getInstance() {
|
||||
return instance.get(); // 返回实例
|
||||
}
|
||||
|
||||
private boolean isNetworkAvailable(Context context) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (connectivityManager != null) {
|
||||
Network network = connectivityManager.getActiveNetwork();
|
||||
if (network != null) {
|
||||
NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
|
||||
return capabilities != null && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||
&& capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,15 +75,16 @@ public class ChangeDeviceInfoUtil {
|
|||
});
|
||||
}
|
||||
|
||||
public static void getAddDeviceInfo(String country, int tag){
|
||||
public static void getAddDeviceInfo(String country, int tag, LoadDeviceCallback callback){
|
||||
LogFileUtil.logAndWrite(android.util.Log.DEBUG, LOG_TAG, "Initializing device info...", null);
|
||||
executorService.submit(() -> {
|
||||
try {
|
||||
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");
|
||||
fallBackToNetworkData(bigoJson, afJson);
|
||||
|
||||
JSONObject bigoDeviceObject = new JSONObject(bigoJson).optJSONObject("device");
|
||||
JSONObject afDeviceObject = new JSONObject(afJson).optJSONObject("device");
|
||||
callback.onLoadDeviceInfo(bigoDeviceObject, afDeviceObject);
|
||||
} catch (IOException | JSONException e) {
|
||||
LogFileUtil.logAndWrite(android.util.Log.ERROR, LOG_TAG, "Error occurred during initialization", e);
|
||||
} catch (Exception e) {
|
||||
|
@ -126,26 +127,33 @@ public class ChangeDeviceInfoUtil {
|
|||
|
||||
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);
|
||||
}
|
||||
int attemptCount = 0;
|
||||
|
||||
// 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);
|
||||
while (true) {
|
||||
attemptCount++;
|
||||
try {
|
||||
json = HttpUtil.requestGet(url);
|
||||
if (json != null && !json.isEmpty()) {
|
||||
LogFileUtil.logAndWrite(android.util.Log.DEBUG, LOG_TAG,
|
||||
"Received " + logKey + " after " + attemptCount + " attempt(s): " + json, null);
|
||||
return json;
|
||||
} else {
|
||||
LogFileUtil.logAndWrite(android.util.Log.WARN, LOG_TAG,
|
||||
"Empty or null response for: " + logKey + ", retrying in 3 seconds...", null);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LogFileUtil.logAndWrite(android.util.Log.WARN, LOG_TAG,
|
||||
"Error fetching " + logKey + " (attempt " + attemptCount + "): " + e.getMessage() + ", retrying in 3 seconds...", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
LogFileUtil.logAndWrite(android.util.Log.ERROR, LOG_TAG,
|
||||
"Retry interrupted for " + logKey, ie);
|
||||
throw new IOException("Retry interrupted for " + logKey, ie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,236 +268,241 @@ public class ChangeDeviceInfoUtil {
|
|||
}
|
||||
|
||||
|
||||
public static void changeDeviceInfo(String current_pkg_name, Context context) {
|
||||
public static void changeDeviceInfo(String current_pkg_name, Context context, JSONObject bigoDeviceObject, JSONObject afDeviceObject) {
|
||||
try{
|
||||
BigoInfo bigoDevice;
|
||||
if (bigoDeviceObject != null) {
|
||||
// BIGO
|
||||
String cpuClockSpeed = bigoDeviceObject.optString("cpu_clock_speed");
|
||||
String gaid = bigoDeviceObject.optString("gaid");
|
||||
String userAgent = bigoDeviceObject.optString("User-Agent");
|
||||
String osLang = bigoDeviceObject.optString("os_lang");
|
||||
String osVer = bigoDeviceObject.optString("os_ver");
|
||||
String tz = bigoDeviceObject.optString("tz");
|
||||
String systemCountry = bigoDeviceObject.optString("system_country");
|
||||
String simCountry = bigoDeviceObject.optString("sim_country");
|
||||
long romFreeIn = bigoDeviceObject.optLong("rom_free_in");
|
||||
String resolution = bigoDeviceObject.optString("resolution");
|
||||
String vendor = bigoDeviceObject.optString("vendor");
|
||||
int batteryScale = bigoDeviceObject.optInt("bat_scale");
|
||||
// String model = deviceObject.optString("model");
|
||||
String net = bigoDeviceObject.optString("net");
|
||||
int dpi = bigoDeviceObject.optInt("dpi");
|
||||
long romFreeExt = bigoDeviceObject.optLong("rom_free_ext");
|
||||
String dpiF = bigoDeviceObject.optString("dpi_f");
|
||||
int cpuCoreNum = bigoDeviceObject.optInt("cpu_core_num");
|
||||
|
||||
BigoInfo bigoDevice;
|
||||
if (bigoDeviceObject != null) {
|
||||
// BIGO
|
||||
String cpuClockSpeed = bigoDeviceObject.optString("cpu_clock_speed");
|
||||
String gaid = bigoDeviceObject.optString("gaid");
|
||||
String userAgent = bigoDeviceObject.optString("User-Agent");
|
||||
String osLang = bigoDeviceObject.optString("os_lang");
|
||||
String osVer = bigoDeviceObject.optString("os_ver");
|
||||
String tz = bigoDeviceObject.optString("tz");
|
||||
String systemCountry = bigoDeviceObject.optString("system_country");
|
||||
String simCountry = bigoDeviceObject.optString("sim_country");
|
||||
long romFreeIn = bigoDeviceObject.optLong("rom_free_in");
|
||||
String resolution = bigoDeviceObject.optString("resolution");
|
||||
String vendor = bigoDeviceObject.optString("vendor");
|
||||
int batteryScale = bigoDeviceObject.optInt("bat_scale");
|
||||
// String model = deviceObject.optString("model");
|
||||
String net = bigoDeviceObject.optString("net");
|
||||
int dpi = bigoDeviceObject.optInt("dpi");
|
||||
long romFreeExt = bigoDeviceObject.optLong("rom_free_ext");
|
||||
String dpiF = bigoDeviceObject.optString("dpi_f");
|
||||
int cpuCoreNum = bigoDeviceObject.optInt("cpu_core_num");
|
||||
|
||||
bigoDevice = new BigoInfo();
|
||||
bigoDevice.cpuClockSpeed = cpuClockSpeed;
|
||||
bigoDevice.gaid = gaid;
|
||||
bigoDevice.userAgent = userAgent;
|
||||
bigoDevice.osLang = osLang;
|
||||
bigoDevice.osVer = osVer;
|
||||
bigoDevice.tz = tz;
|
||||
bigoDevice.systemCountry = systemCountry;
|
||||
bigoDevice.simCountry = simCountry;
|
||||
bigoDevice.romFreeIn = romFreeIn;
|
||||
bigoDevice.resolution = resolution;
|
||||
bigoDevice.vendor = vendor;
|
||||
bigoDevice.batteryScale = batteryScale;
|
||||
bigoDevice.net = net;
|
||||
bigoDevice.dpi = dpi;
|
||||
bigoDevice.romFreeExt = romFreeExt;
|
||||
bigoDevice.dpiF = dpiF;
|
||||
bigoDevice.cpuCoreNum = cpuCoreNum;
|
||||
TaskUtil.setBigoDevice(bigoDevice);
|
||||
try {
|
||||
callVCloudSettings_put(current_pkg_name + ".system_country", systemCountry, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".sim_country", simCountry, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".rom_free_in", String.valueOf(romFreeIn), context);
|
||||
callVCloudSettings_put(current_pkg_name + ".resolution", resolution, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".vendor", vendor, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".battery_scale", String.valueOf(batteryScale), context);
|
||||
callVCloudSettings_put(current_pkg_name + ".os_lang", osLang, context);
|
||||
// callVCloudSettings_put(current_pkg_name + ".model", model, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".net", net, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".dpi", String.valueOf(dpi), context);
|
||||
callVCloudSettings_put(current_pkg_name + ".rom_free_ext", String.valueOf(romFreeExt), context);
|
||||
callVCloudSettings_put(current_pkg_name + ".dpi_f", dpiF, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".cpu_core_num", String.valueOf(cpuCoreNum), context);
|
||||
callVCloudSettings_put(current_pkg_name + ".cpu_clock_speed", cpuClockSpeed, context);
|
||||
callVCloudSettings_put(current_pkg_name + "_gaid", gaid, context);
|
||||
// **User-Agent**
|
||||
callVCloudSettings_put(current_pkg_name + "_user_agent", userAgent, context);
|
||||
// **os_lang**系统语言
|
||||
callVCloudSettings_put(current_pkg_name + "_os_lang", osLang, context);
|
||||
// **os_ver**
|
||||
callVCloudSettings_put(current_pkg_name + "_os_ver", osVer, context);
|
||||
// **tz** (时区)
|
||||
callVCloudSettings_put(current_pkg_name + "_tz", tz, context);
|
||||
} catch (Throwable e) {
|
||||
logAndWrite(android.util.Log.ERROR, "ChangeDeviceInfoUtil", "Error occurred while changing device info", e);
|
||||
throw new RuntimeException("Error occurred in changeDeviceInfo", e);
|
||||
}
|
||||
}
|
||||
|
||||
DeviceInfo deviceInfo;
|
||||
AfInfo afDevice;
|
||||
if (afDeviceObject != null) {
|
||||
String advertiserId = afDeviceObject.optString(".advertiserId");
|
||||
String model = afDeviceObject.optString(".model");
|
||||
String brand = afDeviceObject.optString(".brand");
|
||||
String androidId = afDeviceObject.optString(".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 country = afDeviceObject.optString(".country");
|
||||
String batteryLevel = afDeviceObject.optString(".batteryLevel");
|
||||
String stackInfo = Thread.currentThread().getStackTrace()[2].toString();
|
||||
String product = afDeviceObject.optString(".product");
|
||||
String network = afDeviceObject.optString(".network");
|
||||
String langCode = afDeviceObject.optString(".lang_code");
|
||||
String cpuAbi = afDeviceObject.optString(".deviceData.cpu_abi");
|
||||
int yDp = afDeviceObject.optInt(".deviceData.dim.ydp");
|
||||
|
||||
afDevice = new AfInfo();
|
||||
afDevice.advertiserId = advertiserId;
|
||||
afDevice.model = model;
|
||||
afDevice.brand = brand;
|
||||
afDevice.androidId = androidId;
|
||||
afDevice.xPixels = xPixels;
|
||||
afDevice.yPixels = yPixels;
|
||||
afDevice.densityDpi = densityDpi;
|
||||
afDevice.country = country;
|
||||
afDevice.batteryLevel = batteryLevel;
|
||||
afDevice.stackInfo = stackInfo;
|
||||
afDevice.product = product;
|
||||
afDevice.network = network;
|
||||
afDevice.langCode = langCode;
|
||||
afDevice.cpuAbi = cpuAbi;
|
||||
afDevice.yDp = yDp;
|
||||
TaskUtil.setAfDevice(afDevice);
|
||||
|
||||
String lang = afDeviceObject.optString(".lang");
|
||||
String ro_product_brand = afDeviceObject.optString("ro.product.brand", "");
|
||||
String ro_product_model = afDeviceObject.optString("ro.product.model", "");
|
||||
String ro_product_manufacturer = afDeviceObject.optString("ro.product.manufacturer", "");
|
||||
String ro_product_device = afDeviceObject.optString("ro.product.device", "");
|
||||
String ro_product_name = afDeviceObject.optString("ro.product.name", "");
|
||||
String ro_build_version_incremental = afDeviceObject.optString("ro.build.version.incremental", "");
|
||||
String ro_build_fingerprint = afDeviceObject.optString("ro.build.fingerprint", "");
|
||||
String ro_odm_build_fingerprint = afDeviceObject.optString("ro.odm.build.fingerprint", "");
|
||||
String ro_product_build_fingerprint = afDeviceObject.optString("ro.product.build.fingerprint", "");
|
||||
String ro_system_build_fingerprint = afDeviceObject.optString("ro.system.build.fingerprint", "");
|
||||
String ro_system_ext_build_fingerprint = afDeviceObject.optString("ro.system_ext.build.fingerprint", "");
|
||||
String ro_vendor_build_fingerprint = afDeviceObject.optString("ro.vendor.build.fingerprint", "");
|
||||
String ro_build_platform = afDeviceObject.optString("ro.board.platform", "");
|
||||
String persist_sys_cloud_drm_id = afDeviceObject.optString("persist.sys.cloud.drm.id", "");
|
||||
int persist_sys_cloud_battery_capacity = afDeviceObject.optInt("persist.sys.cloud.battery.capacity", -1);
|
||||
String persist_sys_cloud_gpu_gl_vendor = afDeviceObject.optString("persist.sys.cloud.gpu.gl_vendor", "");
|
||||
String persist_sys_cloud_gpu_gl_renderer = afDeviceObject.optString("persist.sys.cloud.gpu.gl_renderer", "");
|
||||
String persist_sys_cloud_gpu_gl_version = afDeviceObject.optString("persist.sys.cloud.gpu.gl_version", "");
|
||||
String persist_sys_cloud_gpu_egl_vendor = afDeviceObject.optString("persist.sys.cloud.gpu.egl_vendor", "");
|
||||
String persist_sys_cloud_gpu_egl_version = afDeviceObject.optString("persist.sys.cloud.gpu.egl_version", "");
|
||||
String global_android_id = afDeviceObject.optString(".android_id", "");
|
||||
String anticheck_pkgs = afDeviceObject.optString(".anticheck_pkgs", "");
|
||||
String pm_list_features = afDeviceObject.optString(".pm_list_features", "");
|
||||
String pm_list_libraries = afDeviceObject.optString(".pm_list_libraries", "");
|
||||
String system_http_agent = afDeviceObject.optString("system.http.agent", "");
|
||||
String webkit_http_agent = afDeviceObject.optString("webkit.http.agent", "");
|
||||
String com_fk_tools_pkgInfo = afDeviceObject.optString(".pkg_info", "");
|
||||
String appsflyerKey = afDeviceObject.optString(".appsflyerKey", "");
|
||||
String appUserId = afDeviceObject.optString(".appUserId", "");
|
||||
String disk = afDeviceObject.optString(".disk", "");
|
||||
String operator = afDeviceObject.optString(".operator", "");
|
||||
String cell_mcc = afDeviceObject.optString(".cell.mcc", "");
|
||||
String cell_mnc = afDeviceObject.optString(".cell.mnc", "");
|
||||
String date1 = afDeviceObject.optString(".date1", "");
|
||||
String date2 = afDeviceObject.optString(".date2", "");
|
||||
String bootId = afDeviceObject.optString("BootId", "");
|
||||
|
||||
deviceInfo = new DeviceInfo();
|
||||
deviceInfo.lang = lang;
|
||||
deviceInfo.roProductBrand = ro_product_brand;
|
||||
deviceInfo.roProductModel = ro_product_model;
|
||||
deviceInfo.roProductManufacturer = ro_product_manufacturer;
|
||||
deviceInfo.roProductDevice = ro_product_device;
|
||||
deviceInfo.roProductName = ro_product_name;
|
||||
deviceInfo.roBuildVersionIncremental = ro_build_version_incremental;
|
||||
deviceInfo.roBuildFingerprint = ro_build_fingerprint;
|
||||
deviceInfo.roOdmBuildFingerprint = ro_odm_build_fingerprint;
|
||||
deviceInfo.roProductBuildFingerprint = ro_product_build_fingerprint;
|
||||
deviceInfo.roSystemBuildFingerprint = ro_system_build_fingerprint;
|
||||
deviceInfo.roSystemExtBuildFingerprint = ro_system_ext_build_fingerprint;
|
||||
deviceInfo.roVendorBuildFingerprint = ro_vendor_build_fingerprint;
|
||||
deviceInfo.roBuildPlatform = ro_build_platform;
|
||||
deviceInfo.persistSysCloudDrmId = persist_sys_cloud_drm_id;
|
||||
deviceInfo.persistSysCloudBatteryCapacity = persist_sys_cloud_battery_capacity;
|
||||
deviceInfo.persistSysCloudGpuGlVendor = persist_sys_cloud_gpu_gl_vendor;
|
||||
deviceInfo.persistSysCloudGpuGlRenderer = persist_sys_cloud_gpu_gl_renderer;
|
||||
deviceInfo.persistSysCloudGpuGlVersion = persist_sys_cloud_gpu_gl_version;
|
||||
deviceInfo.persistSysCloudGpuEglVendor = persist_sys_cloud_gpu_egl_vendor;
|
||||
deviceInfo.persistSysCloudGpuEglVersion = persist_sys_cloud_gpu_egl_version;
|
||||
TaskUtil.setDeviceInfo(deviceInfo);
|
||||
try {
|
||||
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);
|
||||
callVCloudSettings_put(current_pkg_name + ".lang", lang, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".country", country, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".batteryLevel", batteryLevel, context);
|
||||
callVCloudSettings_put(current_pkg_name + "_screen.optMetrics.stack", stackInfo, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".product", product, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".network", network, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".cpu_abi", cpuAbi, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".lang_code", langCode, context);
|
||||
// **广告标识符 (advertiserId)** 及 **启用状态**
|
||||
boolean isAdIdEnabled = true; // 默认启用广告 ID
|
||||
callVCloudSettings_put(current_pkg_name + ".advertiserIdEnabled", String.valueOf(isAdIdEnabled), context);
|
||||
|
||||
JSONObject displayMetrics = new JSONObject();
|
||||
|
||||
displayMetrics.put("widthPixels", xPixels);
|
||||
|
||||
displayMetrics.put("heightPixels", yPixels);
|
||||
displayMetrics.put("densityDpi", densityDpi);
|
||||
displayMetrics.put("yDp", yDp);
|
||||
callVCloudSettings_put("screen.device.displayMetrics", displayMetrics.toString(), context);
|
||||
|
||||
if (!ShellUtils.hasRootAccess()) {
|
||||
LogFileUtil.writeLogToFile("ERROR", "ChangeDeviceInfoUtil", "Root access is required to execute system property changes");
|
||||
bigoDevice = new BigoInfo();
|
||||
bigoDevice.cpuClockSpeed = cpuClockSpeed;
|
||||
bigoDevice.gaid = gaid;
|
||||
bigoDevice.userAgent = userAgent;
|
||||
bigoDevice.osLang = osLang;
|
||||
bigoDevice.osVer = osVer;
|
||||
bigoDevice.tz = tz;
|
||||
bigoDevice.systemCountry = systemCountry;
|
||||
bigoDevice.simCountry = simCountry;
|
||||
bigoDevice.romFreeIn = romFreeIn;
|
||||
bigoDevice.resolution = resolution;
|
||||
bigoDevice.vendor = vendor;
|
||||
bigoDevice.batteryScale = batteryScale;
|
||||
bigoDevice.net = net;
|
||||
bigoDevice.dpi = dpi;
|
||||
bigoDevice.romFreeExt = romFreeExt;
|
||||
bigoDevice.dpiF = dpiF;
|
||||
bigoDevice.cpuCoreNum = cpuCoreNum;
|
||||
TaskUtil.setBigoDevice(bigoDevice);
|
||||
try {
|
||||
callVCloudSettings_put(current_pkg_name + ".system_country", systemCountry, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".sim_country", simCountry, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".rom_free_in", String.valueOf(romFreeIn), context);
|
||||
callVCloudSettings_put(current_pkg_name + ".resolution", resolution, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".vendor", vendor, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".battery_scale", String.valueOf(batteryScale), context);
|
||||
callVCloudSettings_put(current_pkg_name + ".os_lang", osLang, context);
|
||||
// callVCloudSettings_put(current_pkg_name + ".model", model, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".net", net, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".dpi", String.valueOf(dpi), context);
|
||||
callVCloudSettings_put(current_pkg_name + ".rom_free_ext", String.valueOf(romFreeExt), context);
|
||||
callVCloudSettings_put(current_pkg_name + ".dpi_f", dpiF, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".cpu_core_num", String.valueOf(cpuCoreNum), context);
|
||||
callVCloudSettings_put(current_pkg_name + ".cpu_clock_speed", cpuClockSpeed, context);
|
||||
callVCloudSettings_put(current_pkg_name + "_gaid", gaid, context);
|
||||
// **User-Agent**
|
||||
callVCloudSettings_put(current_pkg_name + "_user_agent", userAgent, context);
|
||||
// **os_lang**系统语言
|
||||
callVCloudSettings_put(current_pkg_name + "_os_lang", osLang, context);
|
||||
// **os_ver**
|
||||
callVCloudSettings_put(current_pkg_name + "_os_ver", osVer, context);
|
||||
// **tz** (时区)
|
||||
callVCloudSettings_put(current_pkg_name + "_tz", tz, context);
|
||||
} catch (Throwable e) {
|
||||
logAndWrite(android.util.Log.ERROR, "ChangeDeviceInfoUtil", "Error occurred while changing device info", e);
|
||||
throw new RuntimeException("Error occurred in changeDeviceInfo", e);
|
||||
}
|
||||
// 设置机型, 直接设置属性
|
||||
ShellUtils.execRootCmd("setprop ro.product.brand " + ro_product_brand);
|
||||
ShellUtils.execRootCmd("setprop ro.product.model " + ro_product_model);
|
||||
ShellUtils.execRootCmd("setprop ro.product.manufacturer " + ro_product_manufacturer);
|
||||
ShellUtils.execRootCmd("setprop ro.product.device " + ro_product_device);
|
||||
ShellUtils.execRootCmd("setprop ro.product.name " + ro_product_name);
|
||||
ShellUtils.execRootCmd("setprop ro.build.version.incremental " + ro_build_version_incremental);
|
||||
ShellUtils.execRootCmd("setprop ro.build.fingerprint " + ro_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.odm.build.fingerprint " + ro_odm_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.product.build.fingerprint " + ro_product_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.system.build.fingerprint " + ro_system_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.system_ext.build.fingerprint " + ro_system_ext_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.vendor.build.fingerprint " + ro_vendor_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.board.platform " + ro_build_platform);
|
||||
|
||||
// Native.setBootId(bootId);
|
||||
// 修改drm id
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.drm.id " + persist_sys_cloud_drm_id);
|
||||
// 电量模拟需要大于1000
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.battery.capacity " + persist_sys_cloud_battery_capacity);
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.gpu.gl_vendor " + persist_sys_cloud_gpu_gl_vendor);
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.gpu.gl_renderer " + persist_sys_cloud_gpu_gl_renderer);
|
||||
// 这个值不能随便改 必须是 OpenGL ES %d.%d 这个格式
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.gpu.gl_version " + persist_sys_cloud_gpu_gl_version);
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.gpu.egl_vendor " + persist_sys_cloud_gpu_egl_vendor);
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.gpu.egl_version " + persist_sys_cloud_gpu_egl_version);
|
||||
} catch (Throwable e) {
|
||||
logAndWrite(Log.ERROR, "ChangeDeviceInfoUtil", "Error occurred in changeDeviceInfo", e);
|
||||
throw new RuntimeException("Error occurred in changeDeviceInfo", e);
|
||||
bigoDeviceObject = null;
|
||||
}
|
||||
|
||||
DeviceInfo deviceInfo;
|
||||
AfInfo afDevice;
|
||||
if (afDeviceObject != null) {
|
||||
String advertiserId = afDeviceObject.optString(".advertiserId");
|
||||
String model = afDeviceObject.optString(".model");
|
||||
String brand = afDeviceObject.optString(".brand");
|
||||
String androidId = afDeviceObject.optString(".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 country = afDeviceObject.optString(".country");
|
||||
String batteryLevel = afDeviceObject.optString(".batteryLevel");
|
||||
String stackInfo = Thread.currentThread().getStackTrace()[2].toString();
|
||||
String product = afDeviceObject.optString(".product");
|
||||
String network = afDeviceObject.optString(".network");
|
||||
String langCode = afDeviceObject.optString(".lang_code");
|
||||
String cpuAbi = afDeviceObject.optString(".deviceData.cpu_abi");
|
||||
int yDp = afDeviceObject.optInt(".deviceData.dim.ydp");
|
||||
|
||||
afDevice = new AfInfo();
|
||||
afDevice.advertiserId = advertiserId;
|
||||
afDevice.model = model;
|
||||
afDevice.brand = brand;
|
||||
afDevice.androidId = androidId;
|
||||
afDevice.xPixels = xPixels;
|
||||
afDevice.yPixels = yPixels;
|
||||
afDevice.densityDpi = densityDpi;
|
||||
afDevice.country = country;
|
||||
afDevice.batteryLevel = batteryLevel;
|
||||
afDevice.stackInfo = stackInfo;
|
||||
afDevice.product = product;
|
||||
afDevice.network = network;
|
||||
afDevice.langCode = langCode;
|
||||
afDevice.cpuAbi = cpuAbi;
|
||||
afDevice.yDp = yDp;
|
||||
TaskUtil.setAfDevice(afDevice);
|
||||
|
||||
String lang = afDeviceObject.optString(".lang");
|
||||
String ro_product_brand = afDeviceObject.optString("ro.product.brand", "");
|
||||
String ro_product_model = afDeviceObject.optString("ro.product.model", "");
|
||||
String ro_product_manufacturer = afDeviceObject.optString("ro.product.manufacturer", "");
|
||||
String ro_product_device = afDeviceObject.optString("ro.product.device", "");
|
||||
String ro_product_name = afDeviceObject.optString("ro.product.name", "");
|
||||
String ro_build_version_incremental = afDeviceObject.optString("ro.build.version.incremental", "");
|
||||
String ro_build_fingerprint = afDeviceObject.optString("ro.build.fingerprint", "");
|
||||
String ro_odm_build_fingerprint = afDeviceObject.optString("ro.odm.build.fingerprint", "");
|
||||
String ro_product_build_fingerprint = afDeviceObject.optString("ro.product.build.fingerprint", "");
|
||||
String ro_system_build_fingerprint = afDeviceObject.optString("ro.system.build.fingerprint", "");
|
||||
String ro_system_ext_build_fingerprint = afDeviceObject.optString("ro.system_ext.build.fingerprint", "");
|
||||
String ro_vendor_build_fingerprint = afDeviceObject.optString("ro.vendor.build.fingerprint", "");
|
||||
String ro_build_platform = afDeviceObject.optString("ro.board.platform", "");
|
||||
String persist_sys_cloud_drm_id = afDeviceObject.optString("persist.sys.cloud.drm.id", "");
|
||||
int persist_sys_cloud_battery_capacity = afDeviceObject.optInt("persist.sys.cloud.battery.capacity", -1);
|
||||
String persist_sys_cloud_gpu_gl_vendor = afDeviceObject.optString("persist.sys.cloud.gpu.gl_vendor", "");
|
||||
String persist_sys_cloud_gpu_gl_renderer = afDeviceObject.optString("persist.sys.cloud.gpu.gl_renderer", "");
|
||||
String persist_sys_cloud_gpu_gl_version = afDeviceObject.optString("persist.sys.cloud.gpu.gl_version", "");
|
||||
String persist_sys_cloud_gpu_egl_vendor = afDeviceObject.optString("persist.sys.cloud.gpu.egl_vendor", "");
|
||||
String persist_sys_cloud_gpu_egl_version = afDeviceObject.optString("persist.sys.cloud.gpu.egl_version", "");
|
||||
String global_android_id = afDeviceObject.optString(".android_id", "");
|
||||
String anticheck_pkgs = afDeviceObject.optString(".anticheck_pkgs", "");
|
||||
String pm_list_features = afDeviceObject.optString(".pm_list_features", "");
|
||||
String pm_list_libraries = afDeviceObject.optString(".pm_list_libraries", "");
|
||||
String system_http_agent = afDeviceObject.optString("system.http.agent", "");
|
||||
String webkit_http_agent = afDeviceObject.optString("webkit.http.agent", "");
|
||||
String com_fk_tools_pkgInfo = afDeviceObject.optString(".pkg_info", "");
|
||||
String appsflyerKey = afDeviceObject.optString(".appsflyerKey", "");
|
||||
String appUserId = afDeviceObject.optString(".appUserId", "");
|
||||
String disk = afDeviceObject.optString(".disk", "");
|
||||
String operator = afDeviceObject.optString(".operator", "");
|
||||
String cell_mcc = afDeviceObject.optString(".cell.mcc", "");
|
||||
String cell_mnc = afDeviceObject.optString(".cell.mnc", "");
|
||||
String date1 = afDeviceObject.optString(".date1", "");
|
||||
String date2 = afDeviceObject.optString(".date2", "");
|
||||
String bootId = afDeviceObject.optString("BootId", "");
|
||||
|
||||
deviceInfo = new DeviceInfo();
|
||||
deviceInfo.lang = lang;
|
||||
deviceInfo.roProductBrand = ro_product_brand;
|
||||
deviceInfo.roProductModel = ro_product_model;
|
||||
deviceInfo.roProductManufacturer = ro_product_manufacturer;
|
||||
deviceInfo.roProductDevice = ro_product_device;
|
||||
deviceInfo.roProductName = ro_product_name;
|
||||
deviceInfo.roBuildVersionIncremental = ro_build_version_incremental;
|
||||
deviceInfo.roBuildFingerprint = ro_build_fingerprint;
|
||||
deviceInfo.roOdmBuildFingerprint = ro_odm_build_fingerprint;
|
||||
deviceInfo.roProductBuildFingerprint = ro_product_build_fingerprint;
|
||||
deviceInfo.roSystemBuildFingerprint = ro_system_build_fingerprint;
|
||||
deviceInfo.roSystemExtBuildFingerprint = ro_system_ext_build_fingerprint;
|
||||
deviceInfo.roVendorBuildFingerprint = ro_vendor_build_fingerprint;
|
||||
deviceInfo.roBuildPlatform = ro_build_platform;
|
||||
deviceInfo.persistSysCloudDrmId = persist_sys_cloud_drm_id;
|
||||
deviceInfo.persistSysCloudBatteryCapacity = persist_sys_cloud_battery_capacity;
|
||||
deviceInfo.persistSysCloudGpuGlVendor = persist_sys_cloud_gpu_gl_vendor;
|
||||
deviceInfo.persistSysCloudGpuGlRenderer = persist_sys_cloud_gpu_gl_renderer;
|
||||
deviceInfo.persistSysCloudGpuGlVersion = persist_sys_cloud_gpu_gl_version;
|
||||
deviceInfo.persistSysCloudGpuEglVendor = persist_sys_cloud_gpu_egl_vendor;
|
||||
deviceInfo.persistSysCloudGpuEglVersion = persist_sys_cloud_gpu_egl_version;
|
||||
TaskUtil.setDeviceInfo(deviceInfo);
|
||||
try {
|
||||
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);
|
||||
callVCloudSettings_put(current_pkg_name + ".lang", lang, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".country", country, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".batteryLevel", batteryLevel, context);
|
||||
callVCloudSettings_put(current_pkg_name + "_screen.optMetrics.stack", stackInfo, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".product", product, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".network", network, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".cpu_abi", cpuAbi, context);
|
||||
callVCloudSettings_put(current_pkg_name + ".lang_code", langCode, context);
|
||||
// **广告标识符 (advertiserId)** 及 **启用状态**
|
||||
boolean isAdIdEnabled = true; // 默认启用广告 ID
|
||||
callVCloudSettings_put(current_pkg_name + ".advertiserIdEnabled", String.valueOf(isAdIdEnabled), context);
|
||||
|
||||
JSONObject displayMetrics = new JSONObject();
|
||||
|
||||
displayMetrics.put("widthPixels", xPixels);
|
||||
|
||||
displayMetrics.put("heightPixels", yPixels);
|
||||
displayMetrics.put("densityDpi", densityDpi);
|
||||
displayMetrics.put("yDp", yDp);
|
||||
callVCloudSettings_put("screen.device.displayMetrics", displayMetrics.toString(), context);
|
||||
|
||||
if (!ShellUtils.hasRootAccess()) {
|
||||
LogFileUtil.writeLogToFile("ERROR", "ChangeDeviceInfoUtil", "Root access is required to execute system property changes");
|
||||
}
|
||||
// 设置机型, 直接设置属性
|
||||
ShellUtils.execRootCmd("setprop ro.product.brand " + ro_product_brand);
|
||||
ShellUtils.execRootCmd("setprop ro.product.model " + ro_product_model);
|
||||
ShellUtils.execRootCmd("setprop ro.product.manufacturer " + ro_product_manufacturer);
|
||||
ShellUtils.execRootCmd("setprop ro.product.device " + ro_product_device);
|
||||
ShellUtils.execRootCmd("setprop ro.product.name " + ro_product_name);
|
||||
ShellUtils.execRootCmd("setprop ro.build.version.incremental " + ro_build_version_incremental);
|
||||
ShellUtils.execRootCmd("setprop ro.build.fingerprint " + ro_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.odm.build.fingerprint " + ro_odm_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.product.build.fingerprint " + ro_product_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.system.build.fingerprint " + ro_system_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.system_ext.build.fingerprint " + ro_system_ext_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.vendor.build.fingerprint " + ro_vendor_build_fingerprint);
|
||||
ShellUtils.execRootCmd("setprop ro.board.platform " + ro_build_platform);
|
||||
|
||||
// Native.setBootId(bootId);
|
||||
// 修改drm id
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.drm.id " + persist_sys_cloud_drm_id);
|
||||
// 电量模拟需要大于1000
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.battery.capacity " + persist_sys_cloud_battery_capacity);
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.gpu.gl_vendor " + persist_sys_cloud_gpu_gl_vendor);
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.gpu.gl_renderer " + persist_sys_cloud_gpu_gl_renderer);
|
||||
// 这个值不能随便改 必须是 OpenGL ES %d.%d 这个格式
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.gpu.gl_version " + persist_sys_cloud_gpu_gl_version);
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.gpu.egl_vendor " + persist_sys_cloud_gpu_egl_vendor);
|
||||
ShellUtils.execRootCmd("setprop persist.sys.cloud.gpu.egl_version " + persist_sys_cloud_gpu_egl_version);
|
||||
} catch (Throwable e) {
|
||||
logAndWrite(Log.ERROR, "ChangeDeviceInfoUtil", "Error occurred in changeDeviceInfo", e);
|
||||
throw new RuntimeException("Error occurred in changeDeviceInfo", e);
|
||||
}
|
||||
afDeviceObject = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.example.studyapp.device;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public interface LoadDeviceCallback{
|
||||
void onLoadDeviceInfo(JSONObject bigoDevice, JSONObject afDevice);
|
||||
}
|
Loading…
Reference in New Issue