1

I'd like to read coordinates from my Huawei P30 Pro via ADB by calling adb shell dumpsys location. However, the output is like:

Last Known Locations:
   gps: Location[gps 11******,14****** ...

They are censored with stars even though the GPS is already turned on.

Any idea?

1 Answer 1

1

It looks like this is a modification that Huawei did by themselves (factual reasons not yet found). In short, the method to print the location's detail was overwritten.

dumpsys command calls the system services' dump method (more detail on this answer on Stack Overflow), and for dumpsys location, the respective service is LocationManagerService.

The dump() method for LocationManagerService (in Android 10, but also no major differences on previous versions) contains code like this:

...

pw.println("  Last Known Locations:");
for (Map.Entry<String, Location> entry : mLastLocation.entrySet()) {
    String provider = entry.getKey();
    Location location = entry.getValue();
    pw.println("    " + provider + ": " + location);
}

...

where it will iterate the last known locations from all location providers and print the name of the provider and its location. Note that the location is an instance of Location objects.

By default, the method to print the detail of the Location object (toString()) contains code like this:

@Override
public String toString() {
    StringBuilder s = new StringBuilder();
    s.append("Location[");
    s.append(mProvider);
    s.append(String.format(" %.6f,%.6f", mLatitude, mLongitude));
    ...

where it will print the latitude and longitude in 6 decimal digits.

For many devices, this is the standard behavior, as shown on Nexus 5 with LineageOS 14.1 (Android 7.1):

 Last Known Locations:
    ...
    fused: Location[fused 1.234567,101.010101 acc=500 et=+12h00m00s000ms]
    ...

The numbers are changed due to privacy reason

By overriding the method, OEMs can customize how dumpsys will display the content. (Note: while Android requires some services not to be modified, location is not one of them)

3
  • Thanks for your useful explanation. So, is there a device independent adb command i may use? In my case (python), i can only work with adb commands...
    – mahack
    Apr 18, 2020 at 10:03
  • @mahack I haven't researched further nor tested it, but perhaps you could install 3rd-party apps that can get the GPS coordinates and output them to logcat, then use adb logcat instead.
    – Andrew T.
    Apr 18, 2020 at 10:45
  • thank you for your idea, I will keep this for a plan B. The problem is that I do not have the possibility to install an app for not having that permission. But I got the problem with that toString() thing, could become a long way.
    – mahack
    Apr 21, 2020 at 9:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .