FxOS Geo Stumbling for Mozilla Location Service
Alphan Chen, FxOS System Team
Mozilla Location Service (MLS)
- An open service which lets devices determine their location based on network infrastructure like WiFi access points and cell towers.
- All data in the MLS database are contributed by users.
- https://location.services.mozilla.com/
1-1
Right Person for MLS :)
1-2
What is "stumble" ??
2-1
GPS Device
GPS Driver
HAL
GonkGPSLocationProvider
GonkGPSGeolocationProvider::LocationCallback
Pack the location info, network infrastructure info into a file (json format) called stumble
2-2
stumbles.json.gz
When stumbles > 15 KB
stumbles.done.json.gz
If the upload file is older than 1day, we try to upload the file.
Each upload is triggered by a new location.
The maxium of upload attempt is 20 times a day.
https://location.services.mozilla.com
2-3
Current Entry Point
- Located at:
- "GonkGPSGeolocationProvider::LocationCallback".
- Function :
- Call "MozStumble" with nsGeoPosition
2-4
2-5
If there is stumble that needed to be uploaded?
Check if there consecutive GPS locations are 30 meters and 3 seconds apart?
False
True
True
False
Exit
Trigger WriteStumbleOnThread with an empty string. Then exit.
Dispatch a RequestCellInfoEvent with StumblerInfo to main thread.
Then exit.
MozStumble
2-6
RequestCellInfoEvent
Set the number of expected Cell-Info responses according to the number of SIM cards.
1. Trigger a cell-tower scan.
Use "GetCellInfoList" with specific callback(nsICellInfoListCallback).
2. Trigger a WiFi AP scan.
Use "GetWifiScanResults" with specific callback(nsIWifiScanResultsReady).
2-7
StumblerInfo
Callback for the scan result of Cell-Tower
Callback for the scan result of WiFi AP
Prepare the string with all needed information. (Location Info/Cell Network/Wifi AP)
Trigger WriteStumbleOnThread to generate a stumble
2-8
stumbles.json.gz
When stumbles > 15 KB
stumbles.done.json.gz
If the upload file is older than 1day, we try to upload the file.
Each upload is triggered by a new location.
The maxium of upload attempt is 20 times a day.
https://location.services.mozilla.com
UploadStumbleRunnable
WriteStumbleOnThread
3-1
WriteStumbleOnThread
GetUploadFileStatus()
Trigger UploadStumbleOnThread
ExistsAndReadyToUpload
NoFile
WriteJSON()
Exists
No action. (stumbles.done.json.gz is less than one day old)
The file will rename from "stumbles.json.gz" to "stumbles.done.json.gz" when the size is over 15KB
3-2
WriteStumbleOnThread
- There is only one file active;
- stumbles.json.gz is being used for writing
- stumbles.done.json.gz is for uploading.
- This thread is guarded so that only one instance is active
3-3
UploadStumbleOnThread
1. Do GeoSubmit [1]
2. Listen several events
(abort, error, load, timeout)
UploadEnded(doDelete=true)
(200 || 400)
other statusCode
Check the XMLHttpRequest status code when observing the events above
UploadEnded(doDelete=false)
The stumble will be deleted if doDelete is true. Otherwise, we will keep the stumble and retry uploading next time.
3-4
UploadStumbleRunnable
- It is managed by WriteStumbleOnThread only
- [1] Geosubmit
3-5
stumbles.json.gz
When stumbles > 15 KB
stumbles.done.json.gz
If the upload file is older than 1 day old, we will try to upload the file.
Each upload is triggered by a new location.
The maximum of upload attempt is 20 times a day.
https://location.services.mozilla.com
UploadStumbleRunnable
WriteStumbleOnThread
3-1
In the end
- Main Bug : 1154435
- We enable stumbling on B2G.
- A special thanks to Garvan Keeley, who involved to this feature deeply and give me lots of help.
- Planning
- related bug 1199395, 1200304, 1200310
Future Work
-
A better event to trigger the upload. Ideally we would preferentially upload when connected to WiFi.
-
Maximum upload currently: 15 KB per day.
-
- Refactoring to a high layer. (a function such as nsGeolocationService::geostumble(nsGeoPosition))
- QC replaces "GonkGPSGeolocationProvider.cpp". They collect the data by themselves.
-
Show the contribution of stumbling in Gaia.
- Bug 1199093
Thanks.
Q & A
number | size |
---|---|
1 item | 609 bytes |
20 - 30 | 15 KB |
Privacy
Stumbler for FxOS phase 1 - Architecture (Draft)
Date-1.json.gz
Date-2.json.gz
Date-3.json.gz
Date-4.json.gz
All files are less than "12.5 KB"
Date-1.json.gz
Date-1.json.gz
Remove
Rename
Rename
Rename
When Data-4.json is more than 12.5 KB
Date-4.json.gz
Date-3.json.gz
Date-2.json.gz
#define OLDEST_FILE_NUMBER 1
#define MAXFILENUM 4
#define MAXFILESIZE_KB 12.5 * 1024
feeding-1.json.gz
Date-1.json.gz
Move to Upload List
Rename
Rename
Rename
When Data-4.json is more than 12.5 KB
feeding-4.json.gz
feeding-3.json.gz
feeding-2.json.gz
upload01.json.gz
Move to Upload List
upload02.json.gz
upload03.json.gz
upload04.json.gz
#define OLDEST_FILE_NUMBER 1
#define MAXUPLOADFILENUM 15
#define MAXFILESIZE_KB 12.5 * 1024
- @dom/system/gonk/mozstumbler/MozStumbler.cpp
- Check if there is stumble that needed to be uploaded.
- (True) Trigger WriteStumbleOnThread with an empty string.
- Check if consecutive GPS locations are 30 meters and 3 seconds apart
- (True) Dispatch RequestCellInfoEvent with StumblerInfo to main thread.
- (False) Pass this location
MozStumble
Stumble Example
{"items":
[{"accuracy":100.000000,
"altitude":0.000000,
"altitudeAccuracy":100.000000,
"heading":0.000000,
"latitude":25.032472,
"longitude":121.566065,
"speed":0.000000,
"timestamp":1439457536722,
"cellTowers":
[{"radioType":"wcdma","asu":14,"cellId":9111196,
"locationAreaCode":11115,"mobileCountryCode":466,"mobileNetworkCode":97,
"psc":108,"serving":1},
{"radioType":"wcdma","asu":12,"psc":109,"serving":0},
{"radioType":"wcdma","asu":10,"psc":292,"serving":0}],
"wifiAccessPoints":
[{"macAddress":"3c1e040a2f0e","signalStrength":-39},
{"macAddress":"dc38e1832980","signalStrength":-50}]
}]
}
- The task of this class
- Trigger a scan of cell-tower.
- connection->GetCellInfoList(mRequestCallback)
- Set the number of expected Cell-Info response according to the number of sim card
- Trigger a scan of wifi AP
- wifi->GetWifiScanResults(mRequestCallback);
- Trigger a scan of cell-tower.
RequestCellInfoEvent
nsRefPtr<StumblerInfo> requestCallback = new StumblerInfo(position);
nsRefPtr<RequestCellInfoEvent> runnable = new RequestCellInfoEvent(requestCallback);
- This class contains
- dom/system/gonk/mozstumbler/MozStumbler.cpp
- (Inherit from nsICellInfoListCallback)
- Callback for the scan result of Cell-Tower
- (Inherit from nsIWifiScanResultsReady)
- Callback for the scan result of Wifi AP
- Dump the information into a single string.
- DumpStumblerInfo()
- Trigger WriteStumbleOnThread with the string to generate a stumble
StumblerInfo
class StumblerInfo final : public nsICellInfoListCallback,
public nsIWifiScanResultsReady
{
public:
...
private:
int mCellInfoResponsesExpected;
int mCellInfoResponsesReceived;
bool mIsWifiInfoResponseReceived;
}
WriteStumbleOnThread
- This class is the entry point to stumbling, in that receives the location+cell+wifi string and writes it to disk, or instead, it calls UploadStumbleRunnable to upload the data.
- Writes will happen until the file reaches maximum size(15KB), then stop. Uploads will happen only when the file is one day old.
- There is only one file active; it is either being used for writing, or for uploading.
- Now the upload is triggered by a location event, this is used as an arbitrary and simple trigger.
- This thread is guarded so that only one instance is active
(Original) FxOS Geo Stumbling for Mozilla Location Service
By Alphan Chen
(Original) FxOS Geo Stumbling for Mozilla Location Service
- 1,108