mirror of
http://gitea.winboll.cc/Studio/WinBoLL.git
synced 2026-06-30 04:22:25 +08:00
修复GPS订阅数据流断裂,打通MainService→广播→ChildService完整链路
- GpsSubscribeResult 增加 latitude/longitude/locationTime 字段及序列化
- GpsSubscribeReceiverService 重写 onCreate/onDestroy 动态注册广播接收器,onStartCommand 读取 SID 并绑定
- GpsSubscribeControlView 启动服务时传递 EXTRA_SUBSCRIBE_SID
- MainService 步长判断通过后调用 sendSubscribeResult();initManager() 补调 initContext(this)
- GpsReceiverChildService{1,2,3} 补调 super.onStartCommand
- AndroidManifest.xml 修正广播 Action 为 cc.winboll.studio.GPS_SUBSCRIBE_CALLBACK
- GpsSubscribeManager/GpsSubscribeObserverReceiver 广播 Extra 键名改用常量
- GpsSubscribeConst 新增 EXTRA_SUBSCRIBE_SID/EXTRA_SUBSCRIBE_RESULT/EXTRA_LOCATION_POINT
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Wed Jun 03 12:37:33 GMT 2026
|
#Thu Jun 04 17:48:23 HKT 2026
|
||||||
stageCount=27
|
stageCount=27
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.11
|
baseVersion=15.11
|
||||||
publishVersion=15.11.26
|
publishVersion=15.11.26
|
||||||
buildCount=37
|
buildCount=43
|
||||||
baseBetaVersion=15.11.27
|
baseBetaVersion=15.11.27
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public final class GpsReceiverChildService1 extends GpsSubscribeReceiverService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
super.onStartCommand(intent, flags, startId);
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public final class GpsReceiverChildService2 extends GpsSubscribeReceiverService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
super.onStartCommand(intent, flags, startId);
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public final class GpsReceiverChildService3 extends GpsSubscribeReceiverService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
super.onStartCommand(intent, flags, startId);
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ import androidx.core.app.NotificationCompat;
|
|||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
import cc.winboll.studio.libgitsion.manager.GpsSubscribeManager;
|
import cc.winboll.studio.libgitsion.manager.GpsSubscribeManager;
|
||||||
import cc.winboll.studio.libgitsion.manager.SubscribeLocationManager;
|
import cc.winboll.studio.libgitsion.manager.SubscribeLocationManager;
|
||||||
|
import cc.winboll.studio.libgitsion.model.GpsSubscribeConst;
|
||||||
import cc.winboll.studio.libgitsion.model.GpsSubscribeMsg;
|
import cc.winboll.studio.libgitsion.model.GpsSubscribeMsg;
|
||||||
|
import cc.winboll.studio.libgitsion.model.GpsSubscribeResult;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -85,6 +87,7 @@ public final class MainService extends Service {
|
|||||||
*/
|
*/
|
||||||
private void initManager() {
|
private void initManager() {
|
||||||
mSubscribeManager = GpsSubscribeManager.getInstance();
|
mSubscribeManager = GpsSubscribeManager.getInstance();
|
||||||
|
mSubscribeManager.initContext(this);
|
||||||
mLocationRuleManager = SubscribeLocationManager.getInstance();
|
mLocationRuleManager = SubscribeLocationManager.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,20 +192,37 @@ public final class MainService extends Service {
|
|||||||
//更新前台通知文案
|
//更新前台通知文案
|
||||||
updateForegroundNotification(locationInfo);
|
updateForegroundNotification(locationInfo);
|
||||||
|
|
||||||
|
double currentLat = location.getLatitude();
|
||||||
|
double currentLng = location.getLongitude();
|
||||||
|
long currentTime = location.getTime();
|
||||||
|
|
||||||
//遍历全部订阅者进行推送规则判断
|
//遍历全部订阅者进行推送规则判断
|
||||||
Map<String, GpsSubscribeMsg> subscribeAllMap = mSubscribeManager.getSubscribeMap();
|
Map<String, GpsSubscribeMsg> subscribeAllMap = mSubscribeManager.getSubscribeMap();
|
||||||
for (Map.Entry<String, GpsSubscribeMsg> entry : subscribeAllMap.entrySet()) {
|
for (Map.Entry<String, GpsSubscribeMsg> entry : subscribeAllMap.entrySet()) {
|
||||||
final String subscribeSid = entry.getKey();
|
final String subscribeSid = entry.getKey();
|
||||||
final GpsSubscribeMsg subscribeConfig = entry.getValue();
|
final GpsSubscribeMsg subscribeConfig = entry.getValue();
|
||||||
|
|
||||||
double currentLat = location.getLatitude();
|
|
||||||
double currentLng = location.getLongitude();
|
|
||||||
|
|
||||||
//判断是否满足推送条件(全订阅/步长阈值)
|
//判断是否满足推送条件(全订阅/步长阈值)
|
||||||
boolean allowPush = mLocationRuleManager.isNeedPush(subscribeSid, currentLat, currentLng);
|
boolean allowPush = mLocationRuleManager.isNeedPush(subscribeSid, currentLat, currentLng);
|
||||||
if (allowPush) {
|
if (allowPush) {
|
||||||
//推送成功后刷新该订阅者基准定点坐标
|
//推送成功后刷新该订阅者基准定点坐标
|
||||||
mLocationRuleManager.updateSubscriberPoint(subscribeSid, currentLat, currentLng);
|
mLocationRuleManager.updateSubscriberPoint(subscribeSid, currentLat, currentLng);
|
||||||
|
mLocationRuleManager.addPushCount(subscribeSid);
|
||||||
|
|
||||||
|
//发送结果广播给订阅者
|
||||||
|
GpsSubscribeResult result = new GpsSubscribeResult(
|
||||||
|
subscribeSid,
|
||||||
|
GpsSubscribeConst.RESULT_SUCCESS,
|
||||||
|
"GPS定位推送",
|
||||||
|
GpsSubscribeConst.GPS_STATE_LOCATED,
|
||||||
|
0,
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
currentLat,
|
||||||
|
currentLng,
|
||||||
|
currentTime
|
||||||
|
);
|
||||||
|
mSubscribeManager.sendSubscribeResult(result);
|
||||||
|
LogUtils.d(TAG, "推送GPS数据至订阅者 SID:" + subscribeSid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|
||||||
<action android:name=".receiver.GpsSubscribeObserverReceiver"/>
|
<action android:name="cc.winboll.studio.GPS_SUBSCRIBE_CALLBACK"/>
|
||||||
|
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public final class GpsSubscribeManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Intent intent = new Intent(GpsSubscribeConst.ACTION_SUBSCRIBE_CALLBACK);
|
Intent intent = new Intent(GpsSubscribeConst.ACTION_SUBSCRIBE_CALLBACK);
|
||||||
intent.putExtra("data",result);
|
intent.putExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_RESULT, result);
|
||||||
appContext.sendBroadcast(intent);
|
appContext.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ public final class GpsSubscribeConst {
|
|||||||
public static final String ACTION_SUBSCRIBE_REQUEST = "cc.winboll.studio.GPS_SUBSCRIBE_REQUEST";
|
public static final String ACTION_SUBSCRIBE_REQUEST = "cc.winboll.studio.GPS_SUBSCRIBE_REQUEST";
|
||||||
public static final String ACTION_SUBSCRIBE_CALLBACK = "cc.winboll.studio.GPS_SUBSCRIBE_CALLBACK";
|
public static final String ACTION_SUBSCRIBE_CALLBACK = "cc.winboll.studio.GPS_SUBSCRIBE_CALLBACK";
|
||||||
|
|
||||||
|
//Intent Extra 键名
|
||||||
|
public static final String EXTRA_SUBSCRIBE_SID = "extra_subscribe_sid";
|
||||||
|
public static final String EXTRA_SUBSCRIBE_RESULT = "extra_subscribe_result";
|
||||||
|
public static final String EXTRA_LOCATION_POINT = "extra_location_point";
|
||||||
|
|
||||||
//超时毫秒
|
//超时毫秒
|
||||||
public static final long SUBSCRIBE_TIME_OUT = 5000;
|
public static final long SUBSCRIBE_TIME_OUT = 5000;
|
||||||
|
|
||||||
|
|||||||
@@ -17,19 +17,28 @@ public final class GpsSubscribeResult implements Parcelable {
|
|||||||
private final int gpsRunningState;
|
private final int gpsRunningState;
|
||||||
private final long realEffectiveInterval;
|
private final long realEffectiveInterval;
|
||||||
private final long currentTimeStamp;
|
private final long currentTimeStamp;
|
||||||
|
private final double latitude;
|
||||||
|
private final double longitude;
|
||||||
|
private final long locationTime;
|
||||||
|
|
||||||
public GpsSubscribeResult(String subscribeUniqueId,
|
public GpsSubscribeResult(String subscribeUniqueId,
|
||||||
int resultCode,
|
int resultCode,
|
||||||
String resultDesc,
|
String resultDesc,
|
||||||
int gpsRunningState,
|
int gpsRunningState,
|
||||||
long realEffectiveInterval,
|
long realEffectiveInterval,
|
||||||
long currentTimeStamp) {
|
long currentTimeStamp,
|
||||||
|
double latitude,
|
||||||
|
double longitude,
|
||||||
|
long locationTime) {
|
||||||
this.subscribeUniqueId = subscribeUniqueId;
|
this.subscribeUniqueId = subscribeUniqueId;
|
||||||
this.resultCode = resultCode;
|
this.resultCode = resultCode;
|
||||||
this.resultDesc = resultDesc;
|
this.resultDesc = resultDesc;
|
||||||
this.gpsRunningState = gpsRunningState;
|
this.gpsRunningState = gpsRunningState;
|
||||||
this.realEffectiveInterval = realEffectiveInterval;
|
this.realEffectiveInterval = realEffectiveInterval;
|
||||||
this.currentTimeStamp = currentTimeStamp;
|
this.currentTimeStamp = currentTimeStamp;
|
||||||
|
this.latitude = latitude;
|
||||||
|
this.longitude = longitude;
|
||||||
|
this.locationTime = locationTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSubscribeUniqueId() {
|
public String getSubscribeUniqueId() {
|
||||||
@@ -56,6 +65,18 @@ public final class GpsSubscribeResult implements Parcelable {
|
|||||||
return currentTimeStamp;
|
return currentTimeStamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getLatitude() {
|
||||||
|
return latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLongitude() {
|
||||||
|
return longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLocationTime() {
|
||||||
|
return locationTime;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -69,6 +90,9 @@ public final class GpsSubscribeResult implements Parcelable {
|
|||||||
dest.writeInt(gpsRunningState);
|
dest.writeInt(gpsRunningState);
|
||||||
dest.writeLong(realEffectiveInterval);
|
dest.writeLong(realEffectiveInterval);
|
||||||
dest.writeLong(currentTimeStamp);
|
dest.writeLong(currentTimeStamp);
|
||||||
|
dest.writeDouble(latitude);
|
||||||
|
dest.writeDouble(longitude);
|
||||||
|
dest.writeLong(locationTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<GpsSubscribeResult> CREATOR = new Creator<GpsSubscribeResult>() {
|
public static final Creator<GpsSubscribeResult> CREATOR = new Creator<GpsSubscribeResult>() {
|
||||||
@@ -80,6 +104,9 @@ public final class GpsSubscribeResult implements Parcelable {
|
|||||||
in.readString(),
|
in.readString(),
|
||||||
in.readInt(),
|
in.readInt(),
|
||||||
in.readLong(),
|
in.readLong(),
|
||||||
|
in.readLong(),
|
||||||
|
in.readDouble(),
|
||||||
|
in.readDouble(),
|
||||||
in.readLong()
|
in.readLong()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -98,6 +125,9 @@ public final class GpsSubscribeResult implements Parcelable {
|
|||||||
bundle.putInt("gpsState", gpsRunningState);
|
bundle.putInt("gpsState", gpsRunningState);
|
||||||
bundle.putLong("realInterval", realEffectiveInterval);
|
bundle.putLong("realInterval", realEffectiveInterval);
|
||||||
bundle.putLong("time", currentTimeStamp);
|
bundle.putLong("time", currentTimeStamp);
|
||||||
|
bundle.putDouble("lat", latitude);
|
||||||
|
bundle.putDouble("lng", longitude);
|
||||||
|
bundle.putLong("locTime", locationTime);
|
||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +138,10 @@ public final class GpsSubscribeResult implements Parcelable {
|
|||||||
bundle.getString("desc"),
|
bundle.getString("desc"),
|
||||||
bundle.getInt("gpsState"),
|
bundle.getInt("gpsState"),
|
||||||
bundle.getLong("realInterval"),
|
bundle.getLong("realInterval"),
|
||||||
bundle.getLong("time")
|
bundle.getLong("time"),
|
||||||
|
bundle.getDouble("lat"),
|
||||||
|
bundle.getDouble("lng"),
|
||||||
|
bundle.getLong("locTime")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public final class GpsSubscribeObserverReceiver extends BroadcastReceiver {
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if(GpsSubscribeConst.ACTION_SUBSCRIBE_CALLBACK.equals(action)){
|
if(GpsSubscribeConst.ACTION_SUBSCRIBE_CALLBACK.equals(action)){
|
||||||
GpsSubscribeResult result = intent.getParcelableExtra("data");
|
GpsSubscribeResult result = intent.getParcelableExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_RESULT);
|
||||||
if(listener != null && result != null){
|
if(listener != null && result != null){
|
||||||
listener.onResultBack(result);
|
listener.onResultBack(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
package cc.winboll.studio.libgitsion.service;
|
package cc.winboll.studio.libgitsion.service;
|
||||||
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
import cc.winboll.studio.libappbase.LogUtils;
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
import cc.winboll.studio.libgitsion.manager.SubscribeLocationManager;
|
||||||
|
import cc.winboll.studio.libgitsion.model.GpsSubscribeConst;
|
||||||
import cc.winboll.studio.libgitsion.model.GpsSubscribeMsg;
|
import cc.winboll.studio.libgitsion.model.GpsSubscribeMsg;
|
||||||
|
import cc.winboll.studio.libgitsion.model.GpsSubscribeResult;
|
||||||
import cc.winboll.studio.libgitsion.model.LocationPoint;
|
import cc.winboll.studio.libgitsion.model.LocationPoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,10 +25,59 @@ public abstract class GpsSubscribeReceiverService extends Service {
|
|||||||
//当前绑定的视图订阅SID
|
//当前绑定的视图订阅SID
|
||||||
protected String bindViewSid;
|
protected String bindViewSid;
|
||||||
|
|
||||||
|
private BroadcastReceiver mCallbackReceiver;
|
||||||
|
|
||||||
public void bindControlSid(String sid){
|
public void bindControlSid(String sid){
|
||||||
this.bindViewSid = sid;
|
this.bindViewSid = sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
LogUtils.d(TAG_PARENT, "Service onCreate, 注册广播接收器");
|
||||||
|
mCallbackReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (GpsSubscribeConst.ACTION_SUBSCRIBE_CALLBACK.equals(intent.getAction())) {
|
||||||
|
GpsSubscribeResult result = intent.getParcelableExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_RESULT);
|
||||||
|
if (result != null && bindViewSid != null
|
||||||
|
&& bindViewSid.equals(result.getSubscribeUniqueId())) {
|
||||||
|
LocationPoint point = new LocationPoint(
|
||||||
|
result.getLatitude(),
|
||||||
|
result.getLongitude(),
|
||||||
|
result.getLocationTime()
|
||||||
|
);
|
||||||
|
GpsSubscribeMsg config = SubscribeLocationManager.getInstance()
|
||||||
|
.getSubscribeConfig(bindViewSid);
|
||||||
|
LogUtils.d(TAG_PARENT, "收到GPS推送,转发至 onReceiveGpsData,SID:" + bindViewSid);
|
||||||
|
onReceiveGpsData(point, config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
registerReceiver(mCallbackReceiver, new IntentFilter(GpsSubscribeConst.ACTION_SUBSCRIBE_CALLBACK));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
if (intent != null && intent.hasExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_SID)) {
|
||||||
|
String sid = intent.getStringExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_SID);
|
||||||
|
bindControlSid(sid);
|
||||||
|
LogUtils.d(TAG_PARENT, "绑定SID:" + sid);
|
||||||
|
}
|
||||||
|
return START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
if (mCallbackReceiver != null) {
|
||||||
|
unregisterReceiver(mCallbackReceiver);
|
||||||
|
mCallbackReceiver = null;
|
||||||
|
LogUtils.d(TAG_PARENT, "广播接收器已注销");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一接收GPS推送入口
|
* 统一接收GPS推送入口
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -139,9 +139,10 @@ public final class GpsSubscribeControlView extends LinearLayout {
|
|||||||
mLocationManager.putSubscribeConfig(currentSubscribeSid, subscribeMsg);
|
mLocationManager.putSubscribeConfig(currentSubscribeSid, subscribeMsg);
|
||||||
mLocationManager.clearPushCount(currentSubscribeSid);
|
mLocationManager.clearPushCount(currentSubscribeSid);
|
||||||
|
|
||||||
//开启订阅自动启动专属接收服务
|
//开启订阅自动启动专属接收服务(携带SID)
|
||||||
if(mBindReceiverServiceClazz != null){
|
if(mBindReceiverServiceClazz != null){
|
||||||
Intent startServiceIntent = new Intent(getContext(), mBindReceiverServiceClazz);
|
Intent startServiceIntent = new Intent(getContext(), mBindReceiverServiceClazz);
|
||||||
|
startServiceIntent.putExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_SID, currentSubscribeSid);
|
||||||
getContext().startService(startServiceIntent);
|
getContext().startService(startServiceIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user