Skip to content
Snippets Groups Projects
Commit 3a7ae547 authored by Raphaël Brulé's avatar Raphaël Brulé
Browse files

Location sharing: stop message

Adds the location sharing stop message for
Android devices. Works with the upcoming iOS
implementation and does not break compatibility
with older versions of this feature.

Change-Id: I9f19e4d5ae7ec312c5b91811e6a209d5a0b89962
parent 46f6fda6
Branches
Tags
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (C) 2004-2020 Savoir-faire Linux Inc. * Copyright (C) 2004-2020 Savoir-faire Linux Inc.
* *
* Authors: Adrien Béraud <adrien.beraud@savoirfairelinux.com> * Authors: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
* Author: Raphaël Brulé <raphael.brule@savoirfairelinux.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -44,6 +45,7 @@ import androidx.annotation.NonNull; ...@@ -44,6 +45,7 @@ import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Date; import java.util.Date;
...@@ -192,6 +194,7 @@ public class LocationSharingService extends Service implements LocationListener ...@@ -192,6 +194,7 @@ public class LocationSharingService extends Service implements LocationListener
.throttleLatest(10, TimeUnit.SECONDS) .throttleLatest(10, TimeUnit.SECONDS)
.map(location -> { .map(location -> {
JSONObject out = new JSONObject(); JSONObject out = new JSONObject();
out.put("type", AccountService.Location.Type.position.toString());
out.put("lat", location.getLatitude()); out.put("lat", location.getLatitude());
out.put("long", location.getLongitude()); out.put("long", location.getLongitude());
out.put("alt", location.getAltitude()); out.put("alt", location.getAltitude());
...@@ -220,9 +223,23 @@ public class LocationSharingService extends Service implements LocationListener ...@@ -220,9 +223,23 @@ public class LocationSharingService extends Service implements LocationListener
else if (ACTION_STOP.equals(action)) { else if (ACTION_STOP.equals(action)) {
if (path == null) if (path == null)
contactLocationShare.clear(); contactLocationShare.clear();
else else {
contactLocationShare.remove(path); contactLocationShare.remove(path);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("type", AccountService.Location.Type.stop.toString());
jsonObject.put("time", Long.MAX_VALUE);
} catch (JSONException e) {
e.printStackTrace();
}
Log.w(TAG, "location send " + jsonObject + " to " + contactLocationShare.size());
StringMap msgs = new StringMap();
msgs.setRaw(CallService.MIME_GEOLOCATION, Blob.fromString(jsonObject.toString()));
Ringservice.sendAccountTextMessage(path.getAccountId(), path.getContactId(), msgs);
}
mContactSharingSubject.onNext(contactLocationShare.keySet()); mContactSharingSubject.onNext(contactLocationShare.keySet());
if (contactLocationShare.isEmpty()) { if (contactLocationShare.isEmpty()) {
......
/* /*
* Copyright (C) 2004-2019 Savoir-faire Linux Inc. * Copyright (C) 2004-2020 Savoir-faire Linux Inc.
* *
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
* Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
* Author: Raphaël Brulé <raphael.brule@savoirfairelinux.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -900,6 +901,8 @@ public class Account { ...@@ -900,6 +901,8 @@ public class Account {
Log.w(TAG, "onLocationUpdate " + location.getPeer() + " " + location.getLatitude() + ", " + location.getLongitude()); Log.w(TAG, "onLocationUpdate " + location.getPeer() + " " + location.getLatitude() + ", " + location.getLongitude());
CallContact contact = getContactFromCache(location.getPeer()); CallContact contact = getContactFromCache(location.getPeer());
switch (location.getType()) {
case position:
ContactLocation cl = new ContactLocation(); ContactLocation cl = new ContactLocation();
cl.timestamp = location.getDate(); cl.timestamp = location.getDate();
cl.latitude = location.getLatitude(); cl.latitude = location.getLatitude();
...@@ -919,7 +922,24 @@ public class Account { ...@@ -919,7 +922,24 @@ public class Account {
if (ls.blockingFirst().timestamp < cl.timestamp) if (ls.blockingFirst().timestamp < cl.timestamp)
((Subject<ContactLocation>) ls).onNext(cl); ((Subject<ContactLocation>) ls).onNext(cl);
} }
return cl.receivedDate.getTime() + LOCATION_SHARING_EXPIRATION_MS; break;
case stop:
forceExpireContact(contact);
break;
}
return LOCATION_SHARING_EXPIRATION_MS;
}
synchronized private void forceExpireContact(CallContact contact) {
Log.w(TAG, "forceExpireContact " + contactLocations.size());
Observable<ContactLocation> cl = contactLocations.remove(contact);
if (cl != null) {
Log.w(TAG, "Contact stopped sharing location: " + contact.getDisplayName());
((Subject<ContactLocation>) cl).onComplete();
mLocationSubject.onNext(contactLocations);
}
} }
synchronized public void maintainLocation() { synchronized public void maintainLocation() {
......
/* /*
* Copyright (C) 2004-2019 Savoir-faire Linux Inc. * Copyright (C) 2004-2020 Savoir-faire Linux Inc.
* *
* Author: Thibault Wittemberg <thibault.wittemberg@savoirfairelinux.com> * Author: Thibault Wittemberg <thibault.wittemberg@savoirfairelinux.com>
* Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
* Author: Raphaël Brulé <raphael.brule@savoirfairelinux.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
*/ */
package cx.ring.services; package cx.ring.services;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
...@@ -129,6 +131,11 @@ public class AccountService { ...@@ -129,6 +131,11 @@ public class AccountService {
Map<String, String> messages; Map<String, String> messages;
} }
public static class Location { public static class Location {
public enum Type {
position,
stop
}
Type type;
String accountId; String accountId;
String callId; String callId;
Uri peer; Uri peer;
...@@ -136,6 +143,10 @@ public class AccountService { ...@@ -136,6 +143,10 @@ public class AccountService {
double latitude; double latitude;
double longitude; double longitude;
public Type getType() {
return type;
}
public String getAccount() { public String getAccount() {
return accountId; return accountId;
} }
...@@ -182,8 +193,15 @@ public class AccountService { ...@@ -182,8 +193,15 @@ public class AccountService {
if (obj.size() < 2) if (obj.size() < 2)
return Maybe.empty(); return Maybe.empty();
Location l = new Location(); Location l = new Location();
JsonElement type = obj.get("type");
if (type == null || type.getAsString().equals(Location.Type.position.toString())) {
l.type = Location.Type.position;
l.latitude = obj.get("lat").getAsDouble(); l.latitude = obj.get("lat").getAsDouble();
l.longitude = obj.get("long").getAsDouble(); l.longitude = obj.get("long").getAsDouble();
} else if (type.getAsString().equals(Location.Type.stop.toString())) {
l.type = Location.Type.stop;
}
l.time = obj.get("time").getAsLong(); l.time = obj.get("time").getAsLong();
l.accountId = msg.accountId; l.accountId = msg.accountId;
l.callId = msg.callId; l.callId = msg.callId;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment