barbeau / gpstest

The #1 open-source Android GNSS/GPS test program
Apache License 2.0
1.78k stars 364 forks source link

feat: Add Wear OS Interface for GPSTest #605

Closed adaext closed 1 year ago

adaext commented 2 years ago

A Wear OS Interface Draft.

Closes https://github.com/barbeau/gpstest/issues/560

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

barbeau commented 1 year ago

In the latest version, looks like you were missing the Application name entry in the manifest. I added that and when launching you now see the dummy lat/lon values.

I also went ahead and added the Flows to the wear Activity. This should be very close to a working state in terms of listening to the GnssStatus and Location updates, although it needs some more debugging - I still don't see the status updates on the screen.

Here's a branch with the changes: https://github.com/barbeau/gpstest/tree/wear-fix-application-manifest

...and the commit: https://github.com/barbeau/gpstest/commit/3d440f234444a6a5c534674b4642a1a949799e1d

adaext commented 1 year ago

In the latest version, looks like you were missing the Application name entry in the manifest. I added that and when launching you now see the dummy lat/lon values.

I also went ahead and added the Flows to the wear Activity. This should be very close to a working state in terms of listening to the GnssStatus and Location updates, although it needs some more debugging - I still don't see the status updates on the screen.

Here's a branch with the changes: https://github.com/barbeau/gpstest/tree/wear-fix-application-manifest

...and the commit: 3d440f2

In the latest version, looks like you were missing the Application name entry in the manifest. I added that and when launching you now see the dummy lat/lon values.

I also went ahead and added the Flows to the wear Activity. This should be very close to a working state in terms of listening to the GnssStatus and Location updates, although it needs some more debugging - I still don't see the status updates on the screen.

Here's a branch with the changes: https://github.com/barbeau/gpstest/tree/wear-fix-application-manifest

...and the commit: 3d440f2

Thank you! It did work. The status doesn't update on the screen because the gnssStatuses is empty. It was created by this val gnssStatuses: List<SatelliteStatus> by signalInfoViewModel.filteredGnssStatuses.observeAsState(emptyList()). I've studied all the links you shared with me and searched from the internet but still don't know why it failed to observe the LiveData.

adaext commented 1 year ago

In the latest version, looks like you were missing the Application name entry in the manifest. I added that and when launching you now see the dummy lat/lon values.

I also went ahead and added the Flows to the wear Activity. This should be very close to a working state in terms of listening to the GnssStatus and Location updates, although it needs some more debugging - I still don't see the status updates on the screen.

Here's a branch with the changes: https://github.com/barbeau/gpstest/tree/wear-fix-application-manifest

...and the commit: 3d440f2 I guess it may be because the gnssStatuses list should be initialized by real GNSS data which the simulator couldn't provide. Could you please help me to test the latest commit on a real device? I don't have an electronic watch.

barbeau commented 1 year ago

I guess it may be because the gnssStatuses list should be initialized by real GNSS data which the simulator couldn't provide. Could you please help me to test the latest commit on a real device? I don't have an electronic watch.

@adaext I took a closer look, and there is actually an exception being thrown by the SharedLocationManager. I added a Log statement in the try/catch block:

        try {
            locationManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER,
                minTimeMillis(context, prefs),
                minDistance(context, prefs),
                callback,
                context.mainLooper
            )
        } catch (e: Exception) {
            Log.e(TAG, "Exception in location flow: $e")
            close(e) // in case of exception, close the Flow
        }

...and here's what is says:

Exception in location flow: java.lang.SecurityException: uid 10080 does not have android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.

So you just need to ask the user for location permissions prior to calling gpsStart() in the MainActivity. You should be able to reproduce this on the Wear emulator and still get location updates there. See the app MainActivity for code to ask for permissions, although you'll need to double-check that this is the same on Wear.

Also, could you add this type of Log statements in any existing try/catch block in all the Shared*Manager classes so we can easily see when a problem happens?