feat(IdleGpsService): 实现圆形轨迹GPS模拟并优化服务启动逻辑

- 重构IdleGpsService,将固定坐标模拟改为圆形轨迹动态生成
- 添加角动量(bearing)递增机制,实现坐标沿圆周持续运动
- 新增calculatePosition()方法,基于锚点坐标和半径计算轨迹位置
- 在MainActivity.onResume中根据空转状态自动启动GPS服务
- 更新build.properties版本号(buildCount 21->23)
This commit is contained in:
2026-05-04 03:41:57 +08:00
parent 79b0320fb9
commit 9d868f216c
3 changed files with 55 additions and 8 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Sun May 03 18:27:26 CST 2026
#Mon May 04 03:36:37 CST 2026
stageCount=20
libraryProject=
baseVersion=15.12
publishVersion=15.12.19
buildCount=21
buildCount=23
baseBetaVersion=15.12.20

View File

@@ -111,6 +111,9 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
protected void onResume() {
super.onResume();
LogUtils.d(TAG, "onResume -> 页面恢复可见");
if (App.isAppIdleRunning()) {
IdleGpsService.getInstance().start();
}
if (mADsBannerView != null) {
mADsBannerView.resumeADs(MainActivity.this);
}

View File

@@ -16,32 +16,72 @@ import java.util.List;
public class IdleGpsService {
private static final long MOCK_INTERVAL_MS = 5000; // 模拟坐标更新间隔5秒
private static final long BEARING_INTERVAL_MS = 1000; // 角动量递增间隔1秒
private static final double EARTH_RADIUS_M = 6371000; // 地球平均半径(米)
private static final double ANCHOR_LAT = 39.9042; // 固定锚点纬度(北京)
private static final double ANCHOR_LON = 116.4074; // 固定锚点经度(北京)
private static final double CIRCLE_RADIUS_M = 50; // 移动轨迹半径(米)
private static IdleGpsService instance;
private final List<MainService.GpsUpdateListener> listeners = new ArrayList<>();
private final Handler handler;
private final Runnable updateRunnable;
private final Runnable bearingRunnable;
private final PositionModel mockPosition;
private boolean isRunning;
private int currentBearing = 1; // 当前角动量度数1-360
private IdleGpsService() {
handler = new Handler(Looper.getMainLooper());
mockPosition = new PositionModel();
mockPosition.setPositionId("mock_idle_pos");
mockPosition.setMemo("空转模拟坐标");
// 默认模拟坐标:北京
mockPosition.setLatitude(39.9042);
mockPosition.setLongitude(116.4074);
updateRunnable = new Runnable() {
@Override
public void run() {
if (isRunning) {
calculatePosition();
notifyListeners(mockPosition);
AppIdleRunningModeHandler.sendIdleLog("模拟GPS数据更新 -> 纬度:" + mockPosition.getLatitude() + ", 经度:" + mockPosition.getLongitude());
AppIdleRunningModeHandler.sendIdleLog("模拟GPS数据更新 -> 纬度:" + mockPosition.getLatitude() + ", 经度:" + mockPosition.getLongitude() + ", 角度:" + currentBearing + "°");
handler.postDelayed(this, MOCK_INTERVAL_MS);
}
}
};
bearingRunnable = new Runnable() {
@Override
public void run() {
if (isRunning) {
currentBearing++;
if (currentBearing > 360) {
currentBearing = 1;
}
handler.postDelayed(this, BEARING_INTERVAL_MS);
}
}
};
}
private void calculatePosition() {
double bearingRad = Math.toRadians(currentBearing);
double angularDistance = CIRCLE_RADIUS_M / EARTH_RADIUS_M;
double anchorLatRad = Math.toRadians(ANCHOR_LAT);
double anchorLonRad = Math.toRadians(ANCHOR_LON);
double newLatRad = Math.asin(
Math.sin(anchorLatRad) * Math.cos(angularDistance) +
Math.cos(anchorLatRad) * Math.sin(angularDistance) * Math.cos(bearingRad)
);
double newLonRad = anchorLonRad + Math.atan2(
Math.sin(bearingRad) * Math.sin(angularDistance) * Math.cos(anchorLatRad),
Math.cos(angularDistance) - Math.sin(anchorLatRad) * Math.sin(newLatRad)
);
mockPosition.setLatitude(Math.toDegrees(newLatRad));
mockPosition.setLongitude(Math.toDegrees(newLonRad));
}
public static IdleGpsService getInstance() {
@@ -57,10 +97,11 @@ public class IdleGpsService {
public void start() {
if (isRunning) return;
isRunning = true;
currentBearing = 1;
AppIdleRunningModeHandler.sendIdleLog("空转GPS服务已启动");
// 通知监听器
notifyStatusChange("空转GPS服务已启动");
handler.post(updateRunnable);
handler.post(bearingRunnable);
}
/**
@@ -70,6 +111,7 @@ public class IdleGpsService {
if (!isRunning) return;
isRunning = false;
handler.removeCallbacks(updateRunnable);
handler.removeCallbacks(bearingRunnable);
notifyStatusChange("空转GPS服务已停止");
AppIdleRunningModeHandler.sendIdleLog("空转GPS服务已停止");
}
@@ -103,14 +145,16 @@ public class IdleGpsService {
private void startMockUpdate() {
if (isRunning) return;
isRunning = true;
// 通知状态变更
currentBearing = 1;
notifyStatusChange("空转GPS服务已启动");
handler.post(updateRunnable);
handler.post(bearingRunnable);
}
private void stopMockUpdate() {
isRunning = false;
handler.removeCallbacks(updateRunnable);
handler.removeCallbacks(bearingRunnable);
notifyStatusChange("空转GPS服务已停止");
}